Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by omveer1997 · Oct 26, 2020 at 11:22 AM · cameramovementdirectionrotaion

i want my plane to fly in camera direction where head is facing (i am newb)please suggest some changes and better method

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class controls : MonoBehaviour { public Rigidbody jet; public float speed; public float Hspeed; public float acceleration; public float maxspeed; public float rotation; public float Rotaccr; public float maxlift; public float lift; public float liftinc; public float yrot = 0; public float xrot = 0;

 void Start()
 {
     jet = GetComponent<Rigidbody>();
 }

 // Update is called once per frame
 void FixedUpdate()
 {
     
     

     float Vaxis = Input.GetAxis("Vertical");

           if(Vaxis>0 && speed<=maxspeed)
             { speed = speed + acceleration * Time.deltaTime; }

     if (Vaxis < 0 && speed >= -maxspeed)
     {
         speed = speed + acceleration * -1 * Time.deltaTime;
     }
     if (Vaxis < 0 && speed >= -maxspeed && transform.position.y < 1)
     { speed = speed + acceleration * -0.0005f * Time.deltaTime; }
     if (Vaxis < 0 && speed>0)
     { speed = 2*(speed + acceleration) * -0.005f * Time.deltaTime; }
     if (Vaxis == 0 && speed >0)
           { speed = speed - acceleration * Time.deltaTime; }
           if (Vaxis == 0 && speed < 0)
           { speed = speed + acceleration * Time.deltaTime; }

           Debug.Log("speed is" + speed);
       

     float Haxis = Input.GetAxis("Horizontal");

                   if (Haxis > 0 && Hspeed <= 20)
                    {
                   
                   Hspeed = Hspeed+(5 * Time.deltaTime); }
                  if (Haxis < 0 && Hspeed >= -20)
                      {
                       
                       Hspeed = Hspeed+ (-5 * Time.deltaTime); }
                   if (Haxis == 0)
                    { Hspeed = 0; }
                   

               
                if (speed==0)
                 { Hspeed = 0; }

     //rotation codes


                      bool Rrot = Input.GetKey("e");
                         bool Lrot = Input.GetKey("q");
               if(Rrot==true && rotation<45 &&transform.position.y>2)
                { rotation = rotation+Rotaccr + 1 * Time.deltaTime;}
               if (Lrot == true && rotation > -45 && transform.position.y > 2)
                { rotation = rotation+(-1) * Time.deltaTime - Rotaccr; }
     
               if (Lrot == false && Rrot == false )
                              { rotation = 0; }


     //lift controls
     bool Blift = Input.GetKey("f");
     if(Blift==true&&speed>acceleration*2&& lift<maxlift)
     { lift = lift + liftinc * Time.deltaTime; }
     
     if(Blift == false && lift>1)
     { lift =lift-lift*Time.deltaTime; }
      




     //jet yaxisi rotation
     
     float VRaxis = Input.GetAxis("Vertical");
     float HRaxis = Input.GetAxis("Horizontal");
     if (lift==0 &&VRaxis==1&&HRaxis==1)
      { yrot = yrot + 1 * Mathf.Abs(VRaxis * HRaxis) * Time.deltaTime; }
     if (lift == 0 && VRaxis == 1 && HRaxis == -1 )
     { yrot = yrot - 1 *Mathf.Abs(VRaxis*HRaxis) *Time.deltaTime; }
     if (lift == 0 && VRaxis == -1 && HRaxis == 1 )
     { yrot = yrot - 1 * Mathf.Abs(VRaxis * HRaxis) * Time.deltaTime; }
     if (lift == 0 && VRaxis == -1 && HRaxis == -1)
     { yrot = yrot + 1 * Time.deltaTime; }
     if(lift==0 &&VRaxis==0&&HRaxis==0)
             { yrot = 0; }



     //xaxis rotation 

     if (speed > 10  && xrot > -360 &&Blift==true)
       { xrot += -0.005f*Time.deltaTime; }
     if (transform.position.y > 10 && xrot < 0 && Blift == true)
     { xrot = xrot+2*Time.deltaTime; }
     if (transform.position.y>10&& xrot < 0 && Blift == false)
     { xrot +=1; }
    








    jet.AddForce(Hspeed, lift, speed);
     
     
    jet.angularVelocity = new Vector3(xrot, yrot, rotation*Time.deltaTime);
     
     


 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

263 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Move player according to the camera direction 1 Answer

Camera Orbit Changing Characters Direction, How? How To Stop It? 0 Answers

Relative Movement Problem 1 Answer

Camera relative movement 0 Answers

Move character in direction its facing 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges