Zones and Ray Casting

Here’s another physics lesson, this has to do with Zones and Ray Casting.

Zones are an empty space (in the shape of a box or ellipsoid) that the marble can travel through.  While not a direct part of the Newton physics engine (at least for 1.53 version I’m using), they do prompt me to cause physical reactions in the game.  Zones are useful for displaying text to the player (such as in a tutorial mode), and anything that can affect the marble without it necessarily touching anything.  Zones can also be attached to widgets… and when they are the effects are determined by the widget.

In rewriting/fixing the Zone system for Marble Maze, I had to make certain effects a little more clever than just an on/off (or in/out) relationship.  For example, with a fan blowing on the marble and affecting it, I would not want the fan’s effect to reach the marble if it was blocked by a wall.  Well, until recently that very phenomenon would happen. 🙂

So let’s introduce the concept of a Ray Cast. Ray casting is the act of having a start point and an end point, and checking to see if something is between them. The Newton physics engine has a ray cast function that is optimized and quite fast, so I use that to determine if there is something permanent between the marble and the widget while inside the Zone.

Green dot is the origin of the Ray Cast, the Red dot is the target, and the Box is the Zone itself

Green dot is the origin of the Ray Cast, the Red dot is the target, and the Box is the Zone itself

The system is fairly dynamic and expandable so I will most likely use Zones for checking collisions between the marble and a powerup or collectible item (coin, gem, etc.).

Comments are closed.