Game Development Community

Problems implementing "gravity" using ConstantForceY...

by Ignis · in Torque Game Builder · 06/20/2010 (7:46 pm) · 1 replies

Hello all,

I hope I'm not repeating a common question here, but what is the best way to set up standard gravity on an object? I used ConstantForceY, which works at a basic level... but now, I have encountered a tricky problem where ConstantForce gradually "pushes" the falling object into solid barriers that I have set up.

For example, assume two objects in my scene:

1) RAMP: a stationary, non-moveable horizontal platform rotated downward to about 30 degrees. Collision Mode is set to "RIGID". Restitution is set to "0" (I don't want bouncing).
2) BALL: a simple ball with ConstantForceY applied. Collision Mode is likewise set to RIGID, and Restitution is "0". "Calculate mass and inertia" is set to true.

In the scene, the ball falls toward the ramp, and it looks about correct compared to real world gravity. The ball then hits the ramp and begins to roll downward, as it should, but then its ConstantForceY starts pushing the ball INTO the ramp, as if the ramp is made of butter... obviously I don't want that!

So, is there a simple solution to this? I considered scripting a collision event to set the ball's ConstantForceY to "0" when it hits the ramp, but then, it probably would stop rolling down the ramp in that case (unless somehow it continues to have momentum and inertia and it continues rolling). I also tried forcing the ramp's Density and Mass very very high, comparable to a 1000-ton brick, but the ball (with very light Mass and Density) still pushes into the ramp after a few seconds of rolling down it...

Anyway, all help and advice is appreciated here. I certainly can't be the first TGB user who has tackled the implementation of basic gravity and collision in a 2D game! :)

Thanks,
Brent

#1
06/24/2010 (2:50 pm)
Well, for a ball, you'd want to make sure the collision poly is set to "CIRCLE". Second, try increasing the number of collision checks per tick. The accuracy of the simulation usually hinges on how dense the collision checks are. Be careful, of course, that you don't end up hogging too much CPU on a simple ball and ramp.

Another thing is you should make the ramp thicker. Sometimes if it's trying to collide with a thin platform, it'll slip through between ticks.
You can do this by creating an invisible trapezoid object and using THAT for collision