I have a game object that is controlled by the player, it can be moved in for directions: up, down, left and right, i want to change its rotation based on the direction it is moving, i have this code:
public void move(Direction dir)
{
switch (dir)
{
case Direction.Left:
body.velocity = new Vector2(-speed, 0);
break;
case Direction.Right:
body.velocity = new Vector2(speed, 0);
break;
case Direction.Up:
body.velocity = new Vector2(0, speed);
break;
case Direction.Down:
body.velocity = new Vector2(0, -speed);
break;
}
//rotate
transform.rotation = Quaternion.LookRotation(body.velocity.normalized, Vector3.back);
direction = dir;
state = State.Walking;
}
the problem is that the game object disappears after the rotation changes, can anyone help me?