- Home /
Get previous velocity of Rigidbody?
Hi,
I know how get the velocity of a Rigidbody, but I need it's velocity which was a second/some frames ago.... I need this so that my car gets damaged if it hits sth at a certain speed, to receive a dent.
This is hard to explain..... I hope I could describe properly. (sry for my poor english)
I just need to store the velocity for a few frames.
I'm scripting in JS.
Are you using OnCollisionEnter? If so, collision.relativeVelocity might help.
Answer by OWiz · Feb 02, 2013 at 04:30 PM
Then store the velocity for a few frames.
Calculate and store the velocity, then make a counter and wait a few frames before you collect the velocity again.
if(frames>3){
GetVelocity();
frames=0;
}else{
frames++'
}
There's no need to count manually, uses something like if(Time.frameCount%5==0) to save the velocity for every 5 frames.
When it hits, the last saved velocity might be last frame, or up to 5 frames ago. It's like each bump will randomly pick from the previous 5 speeds.
Your answer