Help with camera movement

Updated on June 17, 2019 in Answers
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on June 17, 2019

Hello everyone!

 

I was trying to replicate the camera movement from the video Making a Multiplayer FPS in Unity (E02. Movement) – uNet Tutorial.

 

Now my issue is that the player can keep moving the camera upwards with the mouse and it will allow to do a full rotation.

 

What I would like its to stop the camera movement so it wont go into a full rotation like in this video

 

Relevant code:

 

 
[RequireComponent(typeof(Rigidbody))]
 public class PalyerMotor : MonoBehaviour
 {
   [SerializeField]
    privateCameracam;
    privateVector3velocity=Vector3.zero;
    privateVector3rotation=Vector3.zero;
    privateVector3cameraRotation=Vector3.zero;
    privateRigidbodyrb;
    voidStart()
    {
       rb=GetComponent();
    }
    publicvoidMove (Vector3externalVelocity)
    {
       velocity=externalVelocity;
    }
    publicvoidRotate (Vector3externalRotation)
    {
       rotation=externalRotation;
    }
    publicvoidRotateCamera (Vector3externalCameraRotation)
    {
       cameraRotation=externalCameraRotation;
    }
    voidFixedUpdate()
    {
       PerformMovement();
       PerformRotation();
   }
    voidPerformMovement()
    {
       if(velocity!=Vector3.zero)
       {
             rb.MovePosition(rb.position+velocity*Time.fixedDeltaTime);
       }
    }
    voidPerformRotation()
    {
       rb.MoveRotation(rb.rotation*Quaternion.Euler(rotation));
       if (cam!=null)
       {
          cam.transform.Rotate(-cameraRotation);
       }
    }
 }
  • Liked by
Reply