Hi, I’m making a top-down 2d game and I’ve got a problem with player controller. Almost everything is working beside the part when the key is released then player returns to the first position. I don’t know how to store the value of the last key pressed so the player is facing the same direction as the last movement was made. So for example, if the player pressed “D” then it should be aimed in the right direction but instead it gets back to first position. My code so far for this part :
void PlayerInput ()
{
inputMovement = new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical")); tempVector = inputMovement;
Debug.Log(tempVector);
inputRotation = tempVector ;
}
void ProcessMovement()
{
tempVector = rigidbody.GetPointVelocity(transform.position) * Time.deltaTime * 1000; rigidbody.AddForce (-tempVector.x, -tempVector.y, -tempVector.z);
rigidbody.AddForce (inputMovement.normalized * moveSpeed * Time.deltaTime); transform.rotation = Quaternion.LookRotation(inputRotation);
transform.eulerAngles = new Vector3(0,transform.eulerAngles.y + 180,0); transform.position = new Vector3(transform.position.x,0,transform.position.z);
}