Answer the question
In order to leave comments, you need to log in
How to make the character turn towards the mouse cursor?
If the mouse cursor is to the right of the character, then the character turns to the right, if to the left, then to the left.
Answer the question
In order to leave comments, you need to log in
private bool facingRight = false;
public void Update()
{
LookAtCursor();
pos = Camera.main.WorldToScreenPoint(transform.position);
}
public void Flip()
{
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
public void LookAtCursor()
{
if(Input.mousePosition.x < pos.x && !facingRight) Flip();
else if (Input.mousePosition.x > pos.x && facingRight) Flip();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question