- Home /
Needing Help With Relative Motion
Hello, i am having difficulty with my rigid body character. I am making a physics based procedural animation system for first person. I would like my weapon to react with relative motion. For instance if i am on a train or a car it would experience inertia until the object catches up to the speed of the vehicle. Here is my code as is now:
private void UpdateDeltaV()
{
currentVelocity = GetVelocity(); //Returns rigidboy velocity
deltaV = -Vector3.Lerp(deltaV, (currentVelocity - lastVelocity) / Time.fixedDeltaTime, 1); //Finds delta V and then multiplies it by delta time to calculate deltaV
lastVelocity = currentVelocity;
}
This code works well only when the rigid body is moved via velocity changes. But does not take positional information of the transform i am parented to. The idea is that if i land on something i will become parented to that and then that would be used to calculate the delta v each frame.
I have tried changing the velocity readings from the rigid body to positional readings of the player with some really strange results. Here is some simmilar code i tried recently:
currentVelocity = transform.position - lastPosition;
deltaV = -Vector3.Lerp(deltaV, (currentVelocity - lastVelocity) / Time.deltaTime, 1);
lastVelocity = currentVelocity;
lastPosition = transform.position;
This code provided really weird results. Random jittering / very small perceivable movements in my springs for the weapon.
Is there something i am missing to calculate deltaV? I am at a loss here.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
OnCollisionStay only detects collisions after a secondary collision 0 Answers
How can I change friction of a Physic material in script? 1 Answer
Help with 2D physics script 1 Answer