Physics at rest
by Daniel Buckmaster · in Torque Game Engine Advanced · 05/23/2009 (11:06 am) · 3 replies
I'm trying to iron out the kinks in my custom Player movement model, which relies on spring forces to keep the player on the ground. It's working beautifully, except for a little vertical jitter. This is caused by the spring forces fighting the gravity forces, but never coming to equilibrium:
-springs lengthen
-applied spring force becomes smaller than gravity
-the player falls
-springs contract
-spring force becomes greater than gravity
-springs lengthen
Etcetera. How is this usually handled in programmed physics which operate on a timestep? I want the springs to be able to come to equilibrium against the gravity force, so the player will come to rest and stop jittering.
-springs lengthen
-applied spring force becomes smaller than gravity
-the player falls
-springs contract
-spring force becomes greater than gravity
-springs lengthen
Etcetera. How is this usually handled in programmed physics which operate on a timestep? I want the springs to be able to come to equilibrium against the gravity force, so the player will come to rest and stop jittering.
About the author
Studying mechatronic engineering and computer science at the University of Sydney. Game development is probably my most time-consuming hobby!
#2
However, the equilibrium actually tends to take place at about the high 80% extension range. But 90% is my bottom acceptable limit - any lower than that, and the legs will be noticably bent when the character is standing still. The current system looks acceptable in that regard, but I'm not willing to lower the 'tolerance' levels much further.
It seems I need to take a leaf from the Rigid collision system and implement contact forces differently - but 'contacts' in Rigid are already implemented as 'springs', so that might not be much help :P.
I think an elaboration on that idea might be required. If we're in the 'tolerance' deadzone, we can simply adjust the player's velocity (or position) to move gently upwards until the spring is basically fully extended. That way I can extend the tolerance level further down, but end up with the character standing with a longer equilibrium extension.
EDIT: That's proving difficult to do :P. I need to get my head around the differential equations for figuring out how much velocity to add with a given spring extension.
I'm thinking that what I need here is an integrator, which will just solve the problem of jittering outright (I think...). Though I'd be hesitant to fully integrate all the player physics, with an important factor such as the springs, I'd be reasonably happy to give it a go.
EDIT: Okay, I went back and had a more careful attempt at the equilibrium trick. It's working well now! But I'm encountering the exact same problem with friction now ;P. That will probably require a different solution, but we'll see.
05/23/2009 (1:20 pm)
That's an idea I've toyed with, but I don't think I'm doing it right. I have a segment of code for the spring physics, but I only process this if the spring is extended below a certain amount (95%). If the spring is more extended than this, we assume it's fully extended and set the force applied equal to the force due to gravity.However, the equilibrium actually tends to take place at about the high 80% extension range. But 90% is my bottom acceptable limit - any lower than that, and the legs will be noticably bent when the character is standing still. The current system looks acceptable in that regard, but I'm not willing to lower the 'tolerance' levels much further.
It seems I need to take a leaf from the Rigid collision system and implement contact forces differently - but 'contacts' in Rigid are already implemented as 'springs', so that might not be much help :P.
I think an elaboration on that idea might be required. If we're in the 'tolerance' deadzone, we can simply adjust the player's velocity (or position) to move gently upwards until the spring is basically fully extended. That way I can extend the tolerance level further down, but end up with the character standing with a longer equilibrium extension.
EDIT: That's proving difficult to do :P. I need to get my head around the differential equations for figuring out how much velocity to add with a given spring extension.
I'm thinking that what I need here is an integrator, which will just solve the problem of jittering outright (I think...). Though I'd be hesitant to fully integrate all the player physics, with an important factor such as the springs, I'd be reasonably happy to give it a go.
EDIT: Okay, I went back and had a more careful attempt at the equilibrium trick. It's working well now! But I'm encountering the exact same problem with friction now ;P. That will probably require a different solution, but we'll see.
#3
Now I can move on to the more interesting stuff!
05/27/2009 (1:36 am)
Sick of editing :P. I fixed friction with a similar method - you just wait until the system has passed a certain threshold below which it will jitter, and then use a different rule to bring the system to rest. In both cases, I just take the player's velocity and use it to calculate forces to bring the character to a stop.Now I can move on to the more interesting stuff!
Associate Michael Hall
Distracted...