- Home /
Get current speed of an object
How would I get the current speed of an object? I'm trying to create an AI for an enemy tank, and it can't get over bumps in the terrain. I'm using WheelColliders, and I was wondering if there was a way I could set the speed to higher when it slows down when trying to climb a hill. If there was a way to get the speed, I could compare it. If it was less than ten, I could increase the speed by around 10 or something to get it to climb the hill.
Thanks in advance - Elliot Bonneville
Answer by Lipis · Mar 16, 2010 at 05:09 PM
You can check the current velocity from Rigidbody.velocity.
From Unity Script Reference:
In most cases you should not modify the velocity directly, as this can result in unrealistic behaviour. Don't set the velocity of an object every physics step, this will lead to unrealistic physics simulation.
Thanks. Do you know what unit Rigidbody.velocity is in? Is it meters?
it's in meters/second I would guess... if you are using a game unit as a meter :)
I am moving my object with the translate function, and when I call for rigidbody.velocity it is 0 on x y and z, any other ideas?
When you move your object with translate it doesn't really have a speed. It moves as fast as you specify when you translate it. That is your speed.
transform.Translate(0,0,speed * Time.deltaTime);
// /|\
// |
// \___ Your speed.
Your answer
Follow this Question
Related Questions
Reduce steerangle at high speeds 1 Answer
Collision without physical behaviour. 1 Answer
Accelerate slowdown Player movement 0 Answers
How to let player adjust speed of FPC movement 1 Answer
Calculating rigidbody top speed? 3 Answers