- Home /
Calculate vertical velocity?
Hello,in my game rigidbody moves vertically across xy plane colliding with walls. When rigidbody collides with walls at required velocity it destroys them. My problem is that i do not want my rigidbody to destroy walls when it moves horizontally.
Is it possible to calculate object velocity relative to one dimension? Or there another, more simple solution?
Thanks.
Answer by Meltdown · Jan 15, 2012 at 05:41 PM
rigidbody.velocity is a Vector3. SO you can access the x, y, and z components of your rigidbody's velocity.
i.e
var xVelocity = rigidbody.velocity.x;
And if i want to go deaper? is there a way to get the velocity on the x axis and on a certain direction?(right or left...) is it possible???
Answer by ByteSheep · Jan 15, 2012 at 05:49 PM
If you have a character controller on your player, you might be able to read the velocity from there. Here's a wild guess:
var character : CharacterController;
if(character.velocity.y > 0)
{
//do something
}
or without character controller perhaps like this:
if(gameObject.rigidbody.velocity.y > 0)
{
//moving on y axis
}
Your answer