Search Unity

Freelook Cinemachine and Joystick issue

Discussion in 'Editor & General Support' started by Hrach2003, Jul 31, 2020.

  1. Hrach2003

    Hrach2003

    Joined:
    Jan 11, 2020
    Posts:
    1
    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<CharacterController>();
    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);
    }


    }
    }
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    CM Freelook has fields in the inspector where you can set which Input axes control the camera. You'll probably want to change those defaults to something else.
     
    Gregoryl likes this.