- Home /
Is there a way to determine my objects velocity on its local transform?
Maybe i'm asking this wrong but here's what I mean.
I have this object that adds force to it when I have it doing an event.
I also have the float named MovementSpd that determines how fast it is going.
MovementSpd is the Objects Velocity, but the velocity is being determined by the worlds transform or something.
Kind of like this, I have north and south.
When ever my object goes north the MoveSpd will be increased up as Negative(Such as -72.4) But when I move in souths direction the MoveSpd is going up as a Positive number.
So what I need it to do is increase as a positive when the face/forward/front, part of my object is moving forward and decrease when the object is going backwards.
But idk how to go about this. Or know if it's even possible, but I think it is.
Any help would be good.
Answer by drex150 · Sep 22, 2015 at 11:01 PM
You just need to get the magnitude of the velocity instead of just the velocity itself.
float currentSpeed;
Vector3 velocity;
Rigidbody rb;
// Use this for initialization
void Start ()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update ()
{
velocity = rb.velocity;
currentSpeed = velocity.magnitude;
Debug.Log(currentSpeed);
}
}
Your answer
Follow this Question
Related Questions
how do I keep each cloned object at a certain point after trigger 0 Answers
rotate axis of movement 0 Answers
Velocity and Angular Velocity of an object. 2 Answers
Objects not showing axis lines? 0 Answers