- Home /
Torque and stopping the merry go round at the right angle
I have an object. The user inputs an angle for the object to spin towards. It then applies a torque impulse every frame until it detects that it should start applying the same torque in the opposite direction (braking) to get the object to stop spinning at the desired angle.
In the engine that i started this project, I simple applied torque as a fixed impulse of degrees per frame and used the following formula to calculate the distance left to spin if it started applying the brakes.
d=(.5v^2)/f+.5v
This formula doesn't seem to translate over. The final resting place is off by an unpredictable amounts... maybe 3% to 14%... more the bigger the turn.
The formula in Unity looks like this:
float disp = Mathf.Rad2Deg * Mathf.Abs( ( 0.5f * MyGimbal.angularVelocity.sqrMagnitude ) / ( myProfile.impulseRot ) + 0.5f * MyGimbal.angularVelocity.magnitude );
impulseRot is the torque impulse applied each fixed update.
I am wonderingif either I'm using the wrong formula (I'm no physics whiz) or the physics system is unreliable for this application and I should just switch to applying angular speed rather than true rigid body torque.
Maybe the physics system is modelling some aspect of real physics I am overlooking? Maybe I just don't understand angular velocity at all.
Can anyone walk me through this?
The physics system is based on approximations and simplified, fast models. It's not reliable enough for this kind of calculation- if you know where you want the thing to end up, see if you can add in something that 'nudges' it into the right place- constantly correcting any errors which might have accumulated.
That's a good idea... but... hypothetically, if the Unity physics system were perfect... am I taking the right approach there?
Answer by Bunny83 · Nov 12, 2011 at 03:11 AM
I also wouldn't recommend the physics system for such a task. You actually calculate the angular-velocity-vector-length each frame which involves the square-root so at this point you can already have some inaccuracies that adds up quite quickly. Besides that a small error in the acceleration will result in a different speed progression and max speed. The speed adds up to the position so the end result will most likely don't match the expected position.
The simplest way to simulate an accelerated movement might be a hermite-interpolation. Just use this to interpolate your angle directly. It doesn't match a constant acceleration / deceleration but i guess that doesn't really matter :D. It is possible to tweak the internal parameters to change the form of the curve, but they have to fit together. Search the web for a curve that fits your needs.
You could also use a bézier curve which might be easier to be "configured".
Yeah, the issue with the hermite is that the system is based around ais being able to control the physics of spaceships.
But what are you requirements? Do you need to use forces or is it ok to set the velocity directly? In this case you just have to increase the velocity linearly and at a certain point decrease it back to 0.
Do you have other external forces that should be able to influence the object? If that's the case your mathematical approach is quite useless since your "planned" rotation can be altered in between and won't stop at the point you've calculated.