I have a player that teleports around a grid and he always faces the mouse, but when I start teleporting the mouse look slowly breaks until it’s just completely off. Here’s a link showing what I mean: Glitchy Mouse Look - YouTube
This is the code for the player teleporting
protected void Move(char moveDir)
{
switch(moveDir) {
case 'n':
target = new Vector2(transform.position.x, transform.position.y + 1);
break;
case 'e':
target = new Vector2(transform.position.x + 1, transform.position.y);
break;
case 's':
target = new Vector2(transform.position.x, transform.position.y - 1);
break;
case 'w':
target = new Vector2(transform.position.x - 1, transform.position.y);
break;
}
if(control.CanMove(target))
{
transform.position = target;
}
}
and here’s the code for the player looking at the mouse
private void LookAtMouse()
{
Vector2 mousepos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
transform.up = mousepos;
}
both of these are just called in an update method