Hello guys.I have an issue here .So Im making an fps game and it is for android platform.So I I am using a joystick and also freeloock cinemachine camera and when I interact with my joystick to move the character, camera automatically moves.So here the player controller script.Thank you.
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField]
public float speed;
public Camera cam;
private CharacterController _CharacterController;
public FixedJoystick _FixedJoystick;
public float smoothtime = 0.1f;
float turnSmoothVelocity;
Vector3 position;
void Start()
{
_CharacterController = GetComponent();
Cursor.visible = false;
}
void Update()
{
float horizontalMove = _FixedJoystick.Horizontal;
float verticalMove = _FixedJoystick.Vertical;
Vector3 move = new Vector3(horizontalMove, 0f, verticalMove).normalized;
if(move.magnitude >= 0.1f)
{
float targetAngle = Mathf.Atan2(move.x, move.z) + Mathf.Rad2Deg + cam.transform.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, smoothtime);
transform.rotation = Quaternion.Euler(0, angle, 0);
Vector3 moveDir = Quaternion.Euler(0, targetAngle, 0) * Vector3.forward;
_CharacterController.Move(moveDir.normalized * Time.deltaTime * speed);
}
}
}