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
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
About the author
Novice game programmer + artist, graphic/web designer, photographer.
Torque 3D Owner Daniel Balmert
Default Studio Name
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