I am using a virtual joystick to move & rotate the player and a touch swipe system for the camera rotation, The problem is that when I rotate the camera (Let’s say I rotated the camera to 45 degrees on the left) the joystick orientation doesn’t change with the camera & I have to move joystick to the left to move my character forward. What I want is that if I rotate the camera the joystick should also change its orientation so where the camera is facing the character should also move in that direction by moving the joystick up.
Joystick Script that I’m using
private Rigidbody Char;
private Joystick joystick;
void Start()
{
joystick = FindObjectOfType<Joystick>();
Char = GetComponent<Rigidbody>();
}
void Update()
{
Vector3 moveVector = (Vector3.right * joystick.Horizontal + Vector3.forward * joystick.Vertical);
// This line is for player's movement.
Char.velocity = new Vector3(joystick.Horizontal * 3f, Char.velocity.y, joystick.Vertical * 3f);
// This line is for player's rotation.
if (moveVector != Vector3.zero)
{
transform.rotation = Quaternion.LookRotation(moveVector);
}
}
}