- Home /
rigidbody acceleration
Hi, is there any way to obtain the acceleration vector of the rigidbody? In the same way that we can obtain the velocity ej: rigidbody.velocity.
The case is that I have rigidbody objects in my scene, to wich I apply some forces, and then I would like to compute the acceleration of the rigidbody at a certain moment.
Thanks!!
Answer by Jessy · Feb 17, 2011 at 09:51 PM
Instantaneous acceleration doesn't have a meaning in Unity, where rigidbodies are accelerated by forces acting repeatedly at discrete intervals, and stopped without static objects actually exerting forces. You could could do a delta over the smallest possible time step:
acceleration = (rigidbody.velocity - lastVelocity) / Time.fixedDeltaTime;
lastVelocity = rigidbody.velocity;
And if you're talking about acceleration in terms of forces you're applying, instead of measured velocity differences, then just add up whatever you think matters, i.e. stuff you're doing in FixedUpdate plus other forces that happen at irregular intervals.
Answer by rodridkv · Feb 18, 2011 at 09:41 AM
Ok, that's more or less what I thought, but I needed some kind of confirmation, and you gave me that!
I'll calculate the acceleration by derivating the velocity as you say. But I think the instantaneous acceleration of a rigidbody or physic object could be useful... I really don't know.
Thanks anyway!
Answer by HarvesteR · Apr 14, 2011 at 03:59 PM
It's useful for calculating G forces and things like that.
The problem with this method is that there is some numerical "noise" on it...
I have some gauges set up here to measure vertical speed and vertical acceleration and I get some huge jerking movements on the needles...
Vertical speed is more or less ok... it twitches a little when near 0, and some more approaching higher values... It's the derivative of the ship's altitude on the fixed time step (fixedDeltaTime)...
Now, vertical acceleration is the derivative of vertical speed... so it jerks around horribly...
The problem is that this is essentially verlet integration, which is an inherently unstable integration method...
Yeah, Unity really should expose a rigidbody's acceleration... so these things are more convenient.
Cheers
You're right. I have used Euler and Runge-$$anonymous$$utta integration methods but you can't get rid of the noise.
$$anonymous$$aybe with a filter it would work better, but for now the solution fits for my problem.
When you have a system of various rigidbodies interacting with each other, it's very useful knowing the acceleration at any fixed time. So, I agree with you
$$anonymous$$aybe filtering the noise out is the best way to do it... but it does seem like an awfully big hassle just to get a reliable acceleration value off a rigidbody... (which it really won't be if you're filtering too much ;) )
Answer by Elecman · Sep 29, 2014 at 09:10 PM
You can also use the LinearAcceleration() function here:
Your answer
Follow this Question
Related Questions
Overcome drag 1 Answer
How to Tilt a Spaceship Based on Inertia/Acceleration Force Separate from Facing Direction? 2 Answers
strange unrealisticly physic problems about velocity/gravity acceleration 2 Answers
Confusion with AddForce with ForceMode.Acceleration 1 Answer
Simulating Fighter Jet Physics (with addForce () ) 2 Answers