# Determine direction Object is moving (NOT facing)

Hello I am trying to determine the direction a non rotating object is moving. Not the direction the object is facing. So far I have this, but it gives odd results…

``````private var prevLoc : Vector3 = Vector3.zero;
var itsmoving = false;
var direction : String;

function Start () {

}

function Update () {

//if moving stuff
var curVel : Vector3 = (transform.position - prevLoc) / Time.deltaTime;
if ((curVel.z > 0) && ((curVel.z - curVel.x > 0))) {direction = "up";}
else if ((curVel.z < 0) && ((curVel.z - curVel.x < 0))){direction = "down";}
else if ((curVel.x > 0) && ((curVel.x - curVel.z > 0))){direction = "right";}
else if ((curVel.x < 0) && ((curVel.x - curVel.z < 0))) {direction = "left";}

if((curVel.z > 0) || (curVel.x > 0) || (curVel.z < 0) || (curVel.x < 0))
{
// it's moving !!!!
itsmoving = true;

} else if ((curVel.z == 0) && (curVel.x == 0)) {
// it's not moving
itsmoving = false;

}
prevLoc = transform.position;
}
``````

You could just change you curVel.z - curVel.x tests to use the absolute values using Mathf.Abs(curVel.z) - Mathf.Abs(curVel.x) etc.