• 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 DayyanSisson · Aug 05, 2011 at 08:34 PM · controlflightspaceflight

Flight Control/Banking

I have a ship flying in a zero g environment. I have a problem. The problem is that I need to make the ship bank. When I turn, it makes the ship loo unrealistic. The ship follows the mouse, so by pressing forward and moving the mouse to the right, the ship turns to the right & vice versa. But the ship doesn't bank. Is this even possible to do?

This is the only way I could find out how to do this. It works but it's not efficient. I wanted the ship to follow the mouse, but the ship itself would not follow the mouse, but if I put the script on the camera it would. So what I did was make ship "follow" the camera, but made the follow value negative, therefore putting the camera in front. I don't think there are banking answers if this is the way I'm doing it. Is there an even more efficient way to make space flight control? Then maybe the banking answers will work.

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
2
Best Answer

Answer by aldonaletto · Aug 06, 2011 at 03:22 AM

The best way is to have two objects: an empty object to move around, and a child object to do the banking - your model or the first person camera will be attached to this child object. This way the banking will not interfere with the movement, and you can bank sideways and back/forth without any problem.
You can find a similar question with all details about how to do this here.

EDITED: Do the following:
1- Create an empty object and name it "Model";
2- Drag this object to your spaceship (to make it a spaceship child);
3- Zero its rotation and position;
4- Drag your model to this object;
5- Attach the script below to this object;

function Update(){
    var v = Input.GetAxis("Vertical"); // use the same axis that move back/forth
    var h = Input.GetAxis("Horizontal"); // use the same axis that turns left/right
    transform.localEulerAngles.x = v*15; // forth/back banking first!
    transform.localEulerAngles.z = -h*15;  // left/right
}
This script just observes the same axes you use to move the spaceship, and banks according to their values - if you use Input.GetAxis("Mouse X") to turn left/right, for instance, substitute the "Horizontal" name above with "Mouse X".
The spaceship should be an empty object, with the object Model childed to it, and the model itself childed to Model. Your camera target should be set to the spaceship object - as it is already, I suppose.
Comment
Add comment · Show 12 · 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 DayyanSisson · Aug 06, 2011 at 05:38 AM 0
Share

Sorry, I should have been more specific. The camera is behind the ship (third person), not first person.

avatar image aldonaletto · Aug 06, 2011 at 10:37 AM 0
Share

No problem: child the model to the banking object, and set the camera target to the external object. The basic idea is to separate the main movement from the banking, or else you will get completely crazy, because the banking will interfere with the movement and vice versa. Take a look at that answer, and if you can't see how to apply it to your case, post in your question the movement script and I'll tell you what to do.

avatar image DayyanSisson · Aug 06, 2011 at 05:17 PM 0
Share

Thank you for your patience but I posted a problem (below the original question) that might interfere with the advice you are giving me.

avatar image aldonaletto · Aug 06, 2011 at 07:27 PM 0
Share

Which script are you using in your camera? $$anonymous$$ouseLook.cs?

avatar image aldonaletto · Aug 07, 2011 at 05:22 AM 0
Share

Take a look at my answer: I modified it to include the banking script. I hope it works well - let me know if you have problems.

Show more comments
avatar image
0

Answer by davedouggreen · Feb 13, 2021 at 02:53 PM

First of all thanks to @aldonaletto for a good solution. For those weary travelers who find themselves here, looking for a basic solution. Here is my version of the idea suggested above with regards to separating the movement from the banking and which seems to work fine, at least for now. This code was is for a basic game where you control a mosquito and I wanted the insect to bank as it moved from left to right for a bit more realism, and as stated, using this code it now does so.

The structure is exactly as suggested above with parent and child objects and with the respective scripts attached to each of those objects.

PlayerController Script

  void HandleInput()
     {
         horInput = Input.GetAxis("Horizontal");
         vertInput = Input.GetAxis("Vertical");
 
         //rb.AddForce(Vector3.right * speed * horInput);
         //rb.AddForce(Vector3.forward * speed * vertInput);
 
         transform.Translate(Vector3.right * speed * horInput * Time.deltaTime);
         //transform.Translate(Vector3.up * speed * vertInput * Time.deltaTime);
     }

BankingController Script

 void HandleInput()
     {
         horInput = Input.GetAxis("Horizontal");
 
         z = -horInput;
 
         //modifying the Vector3, based on input multiplied by speed and time
         currentEulerAngles += new Vector3(0, 0, z) * Time.deltaTime * rotationSpeed;
 
         //moving the value of the Vector3 into Quanternion.eulerAngle format
         currentRotation.eulerAngles = currentEulerAngles;
 
         //apply the Quaternion.eulerAngles change to the gameObject
         transform.rotation = currentRotation;
     }

Hope someone finds this useful.

Thanks.

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

Space fighter banking 1 Answer

Saitek X52 Throttle value question 2 Answers

How do I use the mouse to control a spacecraft like in this game? 1 Answer

How could I use the mouse as input for a flight control system (and space bar for thrust!) 2 Answers


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