- Home /
 
               Question by 
               wardenamplifies · Apr 15, 2020 at 11:06 AM · 
                vector3quaternionfirst-person-controllerfirst person controllerfirst person  
              
 
              FPS Controller Confusion...
Hello, I am currently following this tutorial about FPS controller movement. I am a beginner. https://www.youtube.com/watch?v=DzO270DH0tk
For the function LookRotation() , where it says Quaternion camTargetRotation and Quaternion bodyTargetRotation; why do we put -camRotationY on the X Axis of the Vector3? Same with bodyRotationX, why do we put it on the Y Axis of the vector3? Wouldn't it make sense for them to be put on their corresponding vector3? I'm a beginner so I don't really understand why this is happening.
Thank you.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class FPSController : MonoBehaviour
 {
     [SerializeField] Transform cam;
     [SerializeField] Rigidbody rb;
 
     [SerializeField] float camRotationSpeed = 5f;
     [SerializeField] float cameraMinimumY = -60f;
     [SerializeField] float cameraMaximumY = 75f;
     [SerializeField] float rotationSmoothSpeed = 10f;
 
     [SerializeField] float walkSpeed = 9f;
     [SerializeField] float runSpeed = 14f;
     [SerializeField] float maxSpeed = 20f;
     [SerializeField] float jumpPower = 30f;
 
     [SerializeField] float extraGravity;
 
     float bodyRotationX;
     float camRotationY;
     Vector3 directionIntentX;
     Vector3 directionIntentY;
     float speed;
 
     public bool grounded;
 
     void Update()
     {
         LookRotation();
     }
 
     void LookRotation()
     {
         //Hides cursor when game entered
         Cursor.visible = false;
         Cursor.lockState = CursorLockMode.Locked;
 
         //Get camera and body rotational values
         bodyRotationX += Input.GetAxis("Mouse X") * camRotationSpeed;
         camRotationY += Input.GetAxis("Mouse Y") * camRotationSpeed;
 
         //Stop our camera from rotating 360 degrees when looking up and down
         camRotationY = Mathf.Clamp(camRotationY, cameraMinimumY, cameraMaximumY);
 
         //Create rotation target and handle rotations of the body and camera
         Quaternion camTargetRotation = Quaternion.Euler(-camRotationY, 0, 0);
         Quaternion bodyTargetRotation = Quaternion.Euler(0, bodyRotationX, 0);
 
         //Handles rotation
         transform.rotation = Quaternion.Lerp(transform.rotation, bodyTargetRotation, Time.deltaTime * rotationSmoothSpeed);
         cam.localRotation = Quaternion.Lerp(cam.localRotation, camTargetRotation, Time.deltaTime * rotationSmoothSpeed);
 
     }
 }
 
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                