I can not configure an adequate change in the character's transform.rotation using a virtual joystick.
To the left and to the right, the character turns like normal - in the screenshot I have shown green arrows.
Up, down and diagonally the character turns wrong - in the screenshot I displayed red arrows
Video how it all works at the moment - https://youtu.be/2NWMwxXn2mc
Explanation for the video:
- From 1 to 6 seconds, I show how the character turns horizontally (right-left) correctly
- From 6 to 24 seconds, I show the character turning incorrectly diagonally and up and down.
How it should work: I pull the joystick up - the character turns up, I pull the joystick down - the character turns down, the same for all sides, including turns diagonally In math, unfortunately, to put it mildly, not strong Script:
public Joystick joystick; float tiltAngle = 180.0f; float smooth = 5.0f; void Update () { Quaternion target = Quaternion.Euler(0, joystick.Vertical * tiltAngle, 0); transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth); Quaternion target2 = Quaternion.Euler(0, joystick.Horizontal * tiltAngle, 0); transform.rotation = Quaternion.Slerp(transform.rotation, target2, Time.deltaTime * smooth); }