- Home /
 
Script For Planes Rotation Using The Mouse Except a Bit Delayed
So I'm pretty new to Unity and have coded a basic plane script. I would like for the players to use both mouse or keyboard. I made a simple mouse script along with some simple planes scripts. The only problem is I would like for the turning of the plane to be delayed so it would not turn instantly. Preferably I would like for the script to be like this: https://www.youtube.com/watch?v=pdrAVzDMz14 except with the camera attached to the plane so a bit different. You don't to write the full script but if you could give the basics and explain a bit so I could learn how it would be greatly appreciated. Thanks!
My Script:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlaneMovement : MonoBehaviour
 {
 
     
 
   public Animator anim;
   public float maxSpeed = 50f;            // Our maximum speed allowed.
   public float decAltSpeed = 20f;        //Decrease Altitude.
   public float incAltSpeed = 20f;        // Increase Altitude.
   public float curSpeed;            // Current Speed;
   public float applySpeed = 4f;        // How much force to apply (Forward).
   
   public float airBrakeForce = 2f;   // Breaks.
   
   public float rollPower = 30f;
 
     public float rotationSpeed = 70f;
   public float yawPower = 30f;
   public float pitchPower = 30f;
 
   public bool Mouse = true;
   private Rigidbody myRigid;        // Our Rigidbody.
   
   void Start(){
       myRigid = GetComponent<Rigidbody>(); 
       applySpeed= 20f;       // Gets the players Rigidbody.
         Cursor.lockState = CursorLockMode.Locked;
 
   }
   
   void FixedUpdate(){
   
   curSpeed = myRigid.velocity.z;
   
   if(curSpeed >= maxSpeed){
       //If our speed maxes out to our maxSpeed we restrict our plane from going any faster.
       applySpeed = curSpeed;
   }
   
   
       if(Input.GetKey(KeyCode.W)){
           //Apply Accelleration
           myRigid.AddRelativeForce(Vector3.forward * applySpeed);
         applySpeed+= 0.30f;
           
       }
       if (Mouse == true)
       {
         transform.Rotate (Vector3.up * rotationSpeed * Input.GetAxis ("Mouse X"));
         transform.Rotate (Vector3.left * rotationSpeed * Input.GetAxis ("Mouse Y"));
       }
       if(Input.GetKey(KeyCode.S)){
           //Apply BREAKS
           myRigid.AddRelativeForce(Vector3.back * airBrakeForce);
           if(curSpeed <= decAltSpeed){
               myRigid.AddRelativeForce(Vector3.down * decAltSpeed);
           }
           }
        
       }
       
       
       void Update(){
      
 
         anim.SetBool("Flying", true);
   
             
         
         if (curSpeed >= maxSpeed || curSpeed>= -40f)
         {
             curSpeed = maxSpeed;
         }
         
         float roll;
         float pitch;
         float yaw;
         yaw = Input.GetAxis("Yaw") * yawPower * Time.deltaTime;
         roll = Input.GetAxis("Roll") * rollPower * Time.deltaTime;
         pitch = Input.GetAxis("Pitch") * pitchPower * Time.deltaTime;
         transform.Rotate(pitch, yaw, roll);
     
         if (curSpeed<= 0f)
         {
             myRigid.AddRelativeForce(Vector3.down * decAltSpeed);
         }
         if (Input.GetKey(KeyCode.UpArrow))
         {
             if(curSpeed >=incAltSpeed){
               myRigid.AddRelativeForce(Vector3.up * incAltSpeed);
           }
         }
               
           }
       
       }
       
   
 
 
 
              Your answer
 
             Follow this Question
Related Questions
Destroying projectile on collision with every object. 1 Answer
A* Pathfinding on enemy to follow the player 0 Answers
Distribute terrain in zones 3 Answers
How can i make changes like in example? 0 Answers