Storing last directional vector for continued movement.

Hey all. I want to be able to store the last known directional vector before it was 0.

	moveDirection = Vector3(h, 0, v);
	Debug.Log (moveDirection);
 
	var movement = moveDirection  * (Time.deltaTime * moveSpeed);
	controller.Move(movement);

Basically, I have a character that moves in moveDirection at the rate of moveSpeed. I already have script in place that slowly makes moveSpeed decline if I’m not pressing in any direction (I’ve debugged the script and have ensured this part works), but because I no longer have a vector of movement, the character stops dead anyway. I want to be able to continue moving in the last direction I pressed before moveDirection was (0.0, 0.0, 0.0). Any help would be greatly appreciated.

EDIT: I forgot to mention. It’s probably obvious, but I’m scripting with javascript. Also, h and v are my horizontal and vertical input axis, retrieved with GetAxisRaw

so basically you want it to continue to slide towards the last moved vector until movespeed reduces it to zero? What you could do is set a an empty game object to the last movable moveDirection say we call it “moveStore”. And then after the next moveDirection = Vector3(); you would compare the latest moveDirection with Vector3.zero(or Vector3(0,0,0). If they’re equal, then assign moveDirection = moveStore; and you got your last heading stored. let me see if I can code it real fast.

//save the last movement
moveStore = moveDirection;

moveDirection = Vector3(h,0,v);

//check if no movement buttons were pressed last call
if(moveDirection == Vector3.zero){
	//no movement detected, use previous moveDirection
	moveDirection = moveStore;
}

var movement = moveDirection *(Time.deltaTime*moveSpeed);
controller.Move(movement);

To continue on Holynub

//check if no movement buttons were pressed last call
if(h==0  v==0)
	//no movement detected, use previous moveDirection
	//Added a slow down modifier.
	moveDirection = moveStore * 0.8;
} else {
	moveDirection = Vector3(h,0,v);
}

Thanks a lot guys. That’s exactly what I needed.