Hi,
I’m sure this is going to be something dumb, but…
I’m trying to get the acceleration of a rigid body using the following code.
localVelocity = _transform.InverseTransformDirection(_rigidBody.velocity);
GetAcceleration();
private void GetAcceleration()
{
acceleration = ((localVelocity - oldVelocity) * Time.fixedDeltaTime)*1000.40f ;
oldVelocity = localVelocity;
}
The object it’s getting the data from is accelerating smoothly at about -0.13 but the numbers I’m getting glitch as sometimes 0 and sometimes -0.25.
(0.02, 0.00, -0.13)acceleration
(0.02, 0.00, -0.13)acceleration
(0.02, 0.00, -0.13)acceleration
(0.02, 0.00, -0.13)acceleration
(0.02, 0.00, -0.12)acceleration
(0.00, 0.00, 0.00)acceleration
(0.03, 0.00, -0.25)acceleration
(0.00, 0.00, 0.00)acceleration
(0.03, 0.00, -0.24)acceleration
(0.01, 0.00, -0.12)acceleration
(0.01, 0.00, -0.12)acceleration
(0.01, 0.00, -0.11)acceleration
(0.01, 0.00, -0.11)acceleration
I think it must be calling the method twice in some frames and skipping some other frames.
I’m not sure how to get it to work.
I’ve tried calling GetAcceleration() in Update and FixedUpdate. I’ve tried multiplying and dividing by Time.deltaTime and Time.fixedDeltaTime but nothing seems to work.
I expected calling it in fixedUpdate would work, but no.
Any ideas?
Thanks in advance.