Category Archives: Physics

Posts describing the physics engine that Marble Maze uses.

I Like To Move It, Move It

So I just added moveable objects. These are important for most physics-based platformers, as they open up a bunch of puzzles for the player to solve. Right now the shapes I have planned are box, plank, and marble. The box and plank can be used as a bridge, the plank can be used as a ramp, and the marble can be used to possibly trigger certain things (land on a switch?).

Next I’ll work on getting enemies into the Editor, which shouldn’t be too bad since they are just like widgets and specials in that regard. And I am looking into adding the ability for some widgets to go on certain slopes. This will mainly be for speed arrows but I’m opening it up to other types, whatever they may be in the future.

We are living in a Material World

…and I am a material g-

Oops, wait a minute! This is supposed to be a physics lesson, not a karaoke contest! 😛

The concept of Material in the Newton physics engine is an important one. In fact, it drives the behavior of all collisions in the system. So of course Marble Maze puts materials to good use. A material is simply an assignment of common properties that can affect the behavior of objects which make contact with it..

Everything in the game is assigned a material. The level terrain itself can be made up of several materials such as Walls, Ice, and Bouncey tiles. I set up the configuration for a material (Ice provides very little friction when contacted by a player marble), and just let the system take care of itself. It really maximizes the effort:results ration when programming physics behavior.

Material checks will also let me know when a marble touches a widget, since all widgets have a “widget material”. It may bounce a marble like a Wall material would, but I hook into this to notify the game engine when a player has made contact with any widget. For instance, a Catapult will fire the arm 4 seconds after the player made contact with it.

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.).

Compound Collision

A Newton physics engine lesson!

A basic moveable, solid collision shape in Newton must be of a convex shape. In order to create a collision that has concave features, you need to “stitch” several convex shapes to create a concave shape. To provide this type of collision, the Newton physics library has the concept of compound collision.

I need a moveable concave type of collision for the cup and stem portion of the catapult. This is where compound collisions come into play. Please see the diagram below to show the steps I had to take to get this in the game.

Setting up a compound collision is easy as A B C and D!

Setting up a compound collision is easy as A B C and D!

  • (A) I built a model of a wedge, to make a wedge collision shape
  • (B) I built a model of the base to make another collision shape (displayed upside down)
  • (C) The wedge collision shapes (top view) were placed around in a circle, along with the base at the bottom
  • (D) Attach the stem (a long box shape) and you have the cup and arm (side view) of the catapult!

I will be showcasing various Newton physics engine concepts in future posts. This one should help you see just how a catapult cup and arm is built in the physics world.