Game Objects; the Vector Field


Hello! after last month’s overview of some of our early graphical effects, I thought I would go into a bit more detail about one of them.

The Vector Field is a utility object that is very simple in theory – a grid is overlaid on the level and each point of this grid contains the current wind speed at that point (or whatever the appropriate thing is for the particular environment). Dynamic graphic objects like particles or soft bodies like hanging cloth can then sample the grid to find out how they should move.

debug overlay

The values in the vector field can be influenced by interactive objects moving past such as the player avatar, or created directly when scripts apply forces. They will then slowly revert to normal – the above image shows a simple debug rendering of the vector field values after a jump.

I originally got the idea from my friend Matricks who used it in Teeworlds. The grid scales quickly with size – especially in 3D environments – which means memory consumption, cache coherency and the processing needed to decay the grid cells become issues. Both Backworlds and Teeworlds are 2D games with reasonably small levels though, so it can be done on the CPU without much overhead – especially since every single cell does not need to be processed every frame. Other solutions could be to simply store the sources of power and their direction, to process everything on the GPU and/or heavily rely on dirty rectangles to figure out what needs to change but for our case the simplicity and flexibility of the vector field is hard to beat.

vectorfieldAbove is a short animation showing a high-speed push through a particle stream and an object reacting to the vector field. This particular vector field has a relatively long decay time which means the particle stream actually changed direction for a short time, a shorter decay time would cause just a few particles to be offset before the stream resumed.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.