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

Resolved FPS look is tilting in direction

Discussion in 'Scripting' started by Thethispointer, Mar 11, 2022.

  1. Thethispointer

    Thethispointer

    Joined:
    Feb 11, 2018
    Posts:
    105
    Hello Forum,

    I get weird camera controls as you can see in the video:


    I am messing around with building a FPS Style Character Controller. I have begun to build it from scratch. I have example assets I am working with. I have created a plane, later I will use terrain, for my character controller to walk on. I am using a Capsule 3D shape, the character controller component, and a camera. I have a script attached to the capsule and the camera.
    They are as follows:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class MoveCharCon : MonoBehaviour
    6. {
    7.     public CharacterController controller;
    8.  
    9.     void Update()
    10.     {
    11.         transform.Rotate(transform.up, -Input.GetAxis("Mouse X") * 7); ;
    12.  
    13.         if (Input.GetKey(KeyCode.W))
    14.             controller.Move(transform.forward * Time.deltaTime * 5);
    15.  
    16.         if (Input.GetKey(KeyCode.S))
    17.             controller.Move(-transform.forward * Time.deltaTime * 5);
    18.  
    19.         if (Input.GetKey(KeyCode.A))
    20.             controller.Move(-transform.right * Time.deltaTime * 5);
    21.  
    22.         if (Input.GetKey(KeyCode.D))
    23.             controller.Move(transform.right * Time.deltaTime * 5);
    24.     }
    25. }
    26.  
    AND

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class MoveCamera : MonoBehaviour
    6. {
    7.    
    8.     void Update()
    9.     {
    10.         transform.Rotate(transform.right, -Input.GetAxis("Mouse Y") * 3);
    11.     }
    12. }
    13.  
     
  2. LilFire

    LilFire

    Joined:
    Jul 11, 2017
    Posts:
    74
    In your camera script, you need to use Vector3.right, not transform.right
     
    Thethispointer likes this.
  3. LilFire

    LilFire

    Joined:
    Jul 11, 2017
    Posts:
    74
    Or you need to specify you want to use world space with your camera axis.
    Code (CSharp):
    1. transform.Rotate(transform.right, -Input.GetAxis("Mouse Y") * 3, Space.World);
     
    Thethispointer likes this.
  4. Thethispointer

    Thethispointer

    Joined:
    Feb 11, 2018
    Posts:
    105
    Thank you I will test this soon!
     
  5. Thethispointer

    Thethispointer

    Joined:
    Feb 11, 2018
    Posts:
    105
    Thank you this works!