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 voxsar1 · Feb 07, 2012 at 08:50 AM · mouse controlaerodynamics

Mouse based based aeroplane movement

I tried to move a aeroplane for my game using this following script below

 var horizontalSpeed : float = 2.0;
 var verticalSpeed : float = 2.0;
 
 function FixedUpdate () {
     Screen.showCursor = false; //hide the mouse cursor in game
 
     // Get the mouse delta. This is not in the range -1...1
     var h : float = horizontalSpeed * Input.GetAxis ("Mouse X");
     var v : float = verticalSpeed * Input.GetAxis ("Mouse Y");
     transform.Rotate (-v, h, 0);
 }

it is used together with the following script

 var speed = 20;
 function Update () {
     if (Input.GetKey(KeyCode.UpArrow)){
         speed +=2;
     }
     if (Input.GetKey(KeyCode.DownArrow)){
         speed -=2;
     }
 transform.Translate(Vector3.forward *speed* Time.deltaTime);
 }

the up/down arrow keys increase and decrease the speed, problem is it does not work excatly as i expect does anyone have any input or suggestions for the code

my objective is to get the plane to move up, down, right, left

but the 'left side to right side' tilt of the plane (Roll), is controlled by the left and right arrow keys, but the plane keeps turning upside down after moveing the mouse for a while

I need it to turn where i point, but (the roll is done from the left/right keys), what is going wrong here, (I am new to unity script, but i learnt java and javascript for web development)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by tonydemot · Feb 08, 2012 at 05:24 AM

you can add a mathf.clamp to clamp the rotation to a certain degree or do you want it to spin around ?

Comment
Add comment · Show 1 · Share
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
avatar image voxsar1 · Feb 08, 2012 at 05:13 PM 0
Share

Thanks but i don't know how mathf does clamping like that?, well i don;t want it to spin around, i want it to move like the 1st person script, but roll when turning left or right, and pitching up and down when increase up and down

avatar image
0

Answer by aliakbo · Feb 08, 2012 at 07:11 PM

Your problem is here

 var speed = 20;
  function Update () {
      if (Input.GetKey(KeyCode.UpArrow)){
         speed +=2;
      }
      if (Input.GetKey(KeyCode.DownArrow)){
         speed -=2;
      }
  transform.Translate(Vector3.forward*speed* Time.deltaTime);
  }

As you can see,

   speed +=2;

Speed will constantly increase while you are holding down the up/down arrow. You could restrict the limit on speed by putting if in a if statement

 if( speed< 20)
      speed +=2;
Comment
Add comment · Show 1 · Share
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
avatar image voxsar1 · Feb 09, 2012 at 01:20 AM 0
Share

Thanks the movement can be limited, true but my real problem is the movement using the mouse, i need the aeroplane to be directed by the mouse, can you help me with that

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

7 People are following this question.

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

Related Questions

Reseting materials color after mass selecting them during run time? 1 Answer

Yaw Pitch Roll order? 0 Answers

RTS movement not working properly 1 Answer

mouse project settings 0 Answers

Trying to keep an object 1.5 above the terrain at all times 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