Game Development Community

Top down ball Physics

by Matt Huston · in Torque Game Builder · 07/08/2006 (12:45 pm) · 3 replies

I am thinking of creating a demo for a pool game that has elevation changes. I am looking for some direction on how I would accomplish this. So basically the ball would roll on a normal surface, hit a slope up or down, gain or lose speed based on this. Any ideas from anyone?

#1
07/08/2006 (8:55 pm)
Basically you will be simulating a depth. You could have triggers with a "slope" value and when your ball enters that trigger you would alter the constant force on the ball.

For example, create a t2dTrigger, place it where you want the ball to roll downward and set its collision polygon to the edge of the slope. Lets pretend its a northwestern slope - you would create a dynamic field on that trigger called "slope" with a vector in the direction gravity would pull the ball, like "-10 -10". Set your trigger's class field to "SlopeTrigger". Then you would write an onEnter callback for the SlopeTrigger class:

function SlopeTrigger::onEnter(%this, %object)
{
   %object.setConstantForce(%this.slope, true);
}


You should also consider seting the collision masks on your ball and your triggers and putting a check in your onEnter callback to make sure %object is a ball. Also, this is just one way to do it. I'm sure there are others.
#2
07/08/2006 (9:54 pm)
Also, to simplify things: if you have a lot of flat areas you might want to make an onLeave callback for your triggers that sets the constant force back to zero.
#3
07/09/2006 (12:47 pm)
Thanks, was having a brain cramp and forgot about the onEnter callback.