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 thenachotech1113 · Mar 28, 2014 at 11:23 PM · forcevectorvector2

Switch force from horizontal to vertical

Hello everyone, i am attempting to make a VTOL(vertical take off and landing) aircraft, kind of like the CoD MW2 Osprey, and i want the thrust force to be able to apply on the angle of the engine (not only 0 and 90 but any angle in between). here is the way i am trying to do it:

 public class Flight_Script : MonoBehaviour {
 
 
     public float acceleration;
     public float thrust;
     public float thrustDir;
 
     public Vector3 vectorThrust;
 
 
     void Update () {
     
 //thrust
         vectorThrust = new Vector3 (thrust * Mathf.Cos(thrustDir), thrust * Mathf.Sin(thrustDir), 0);
 
         thrustDir -= Input.GetAxis ("Mouse ScrollWheel") * 10;
         thrustDir = Mathf.Clamp (thrustDir, 0, 90);
 
         thrust += Input.GetAxis ("Vertical") * acceleration;
     }

btw i deleted a lot from this script that has nothing to do with the thryst, if i have a missing bracket i probably deleted it by mistake. anyway, the problem i have is that when the engine rot is 90 degrees the x is something like a 45% of the thrust, and the y force is something like an 89% of the thrust. i have recently seen 2D vectors in physics and if i recall corectly that is how its done. thank you all

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by robertbu · Mar 28, 2014 at 11:38 PM

One issue is that Mathf.Cos() and Mathf.Sin() takes radians for input, not degrees, so this line should be:

    vectorThrust = new Vector3 (thrust * Mathf.Cos(thrustDir * Mathf.Deg2Rad), thrust * Mathf.Sin(thrustDir * Mathf * Deg2Rad), 0);

Note as an alternative, you could do use an Quaternion.AngleAxis() for the rotation. Something like:

 vectorThrust = Quaternion.AngleAxis(thrustDir, Vector3.forward) * Vector3.right;

Based on your code above, I'm assuming this is a 2D game. I don't know your specific setup. You may want to use another base vector (Vector3.left, Vector3.down), and you may need Vector3.back instead of Vector3.forward. But the concept is the same. You are just picking some base vector and rotating it around the word 'z' axis by angle.

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 thenachotech1113 · Mar 28, 2014 at 11:55 PM 0
Share

thanks a lot, it is actualy a 3d game but i dont need the plane engines to rotate left and right, at lest for now. but thanks for noting that, since its a 3d game, i should probably take in account that when i use the actual engine rotation it should use localRotation.

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

20 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

Related Questions

rigidbody problem 1 Answer

Why the object being moved is faster than the rest? 1 Answer

Get/set vector 3 causing problems 0 Answers

How to make a Vector with the same angle as a certain object? 1 Answer

Rotational Force 0 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