Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

My Camera rotates faster than my character model does.

Discussion in 'Scripting' started by Cubingle, Aug 21, 2020.

  1. Cubingle

    Cubingle

    Joined:
    Aug 2, 2020
    Posts:
    2
    I'm making a FPS game. But when I rotate my camera and mouse it has my camera move faster. Resulting in my camera being at a different rotation than my character.

    Code (CSharp):
    1. x = Input.GetAxis("Mouse X") * sens * sensmulti;
    2.         y = Input.GetAxis("Mouse Y") * sens * sensmulti;
    3.  
    4.         Vector3 rot = camera.transform.localRotation.eulerAngles;
    5.        
    6.         desiredX = rot.y + x;
    7.        
    8.         //Rotate, and also make sure we dont over- or under-rotate.
    9.         xRotation -= y;
    10.         xRotation = Mathf.Clamp(xRotation, -90f, 90f);
    11.  
    12.         //Perform the rotations
    13.         camera.transform.localRotation = Quaternion.Euler(xRotation, desiredX, 0);
    14.         orientation.transform.localRotation = Quaternion.Euler(0, desiredX, 0);
    15.         player.transform.localRotation = Quaternion.Euler(0, desiredX, 0);
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    Line 13 and Line 15 both rotate on the Y axis and hence they "stack," as they are separate transforms.

    Perhaps change line 13 to be (xRotation, 0, 0) ? Just a guess... might have other unintended consequences.
     
  3. Cubingle

    Cubingle

    Joined:
    Aug 2, 2020
    Posts:
    2
    This made them move at the same rate but it only allowed the player and camera to move a slight amount.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,336
    What is orientation? Is this a project to learn how to do an FPS controller? Because you can get those for free... :) You might want to download five or six FPS controllers and check out how they work, then make your own...

    Seems you only need to rotate the player in the Y axis, and rotate the camera in the X axis... so what is orientation?