A
A
Alexander2020-08-28 21:55:56
Unity
Alexander, 2020-08-28 21:55:56

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

2 answer(s)
A
Alexander, 2020-09-02
@Wabbaka

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();
}

W
WasTabon, 2020-08-29
@WasTabon

How to make the player turn behind the cursor like in Top Down Shooter Unity3D 2019? ?)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question