Search Unity

My cam wont rotate 360

Discussion in 'Getting Started' started by unity_wewdvrBtyO5f6g, Dec 10, 2019.

  1. unity_wewdvrBtyO5f6g

    unity_wewdvrBtyO5f6g

    Joined:
    Dec 10, 2019
    Posts:
    1
    public class Camera_movment : MonoBehaviour {

    public Transform player_cam, center_point;
    public float distance, max_height, min_height, orbiting_speed, vertical_speed;
    float height;

    void Update()
    {
    center_point.position = gameObject.transform.position + new Vector3(0, 1.57f, 0);
    center_point.eulerAngles += new Vector3(0, Input.GetAxis("Mouse X") * Time.deltaTime * orbiting_speed, 0);
    height += Input.GetAxis("Mouse Y") * Time.deltaTime * -vertical_speed;
    height = Mathf.Clamp(height, min_height, max_height);
    }

    void LateUpdate()
    {
    player_cam.position = center_point.position + center_point.forward * -1 * distance + Vector3.up * height;
    player_cam.LookAt(center_point);
    }
    }
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Figure out if the problem is with rotating your center_point, or positioning your player_cam. You say your problem is with rotating your cam, but you code doesn't actually do any rotation of the cam other than use LookAt. So obviously the problem is elsewhere than rotating the cam.

    It would help if you'd actually state what the code is doing instead of just posting the code and expecting everyone else to figure that out for you.

    I'm suspicious of any line of code which includes lots of math, operators with different precedence, and zero use of parenthesis.
     
    Last edited: Dec 13, 2019