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 AndreasX12 · Nov 30, 2013 at 07:51 PM · rotationworldrollflight

Move object

Hi, I'm trying to make my plane fly to the left using a rigidbody.

This is my code in FixedUpdate:

transform.rigidbody.AddRelativeForce(Vector3.right * 100);

This should basically move it to the right, and it works perfectly when there is no roll. (The red line in the Picture shows that it's "following the rotation").

I'm trying to make the plane go right no matter how much roll/rotation there is (The green line in the picture).

alt text

How is this possible?

Thanks, Andreas

dir.png (354.9 kB)
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 Tomer-Barkan · Nov 30, 2013 at 08:01 PM

You're using AddRelativeForce, which is exactly that, it adds force relative to the plane's right, instead of world right. The plane's right is always it's right wing, so when it's rolled, it's not exactly right...

You can use rigidbody.AddForce() instead, which will apply the force to the absolute direction that you use.

You can read here about other's physics-based plane game, though it might be more complicated than what you're trying to achieve.

Edit:

Ok, so now that I understand correctly, you want it to go plane-relative left/right, but only in the X/Z plane, while keeping Y constant.

I suggest you use transform.right to calculate the world direction of your plane's right. Then set the the Y of the result to be 0, and normalize it to be of magnitude 1. Then you have the world direction of your plane's right, but flattened so that the world Y of the vector is 0 (basically a projection on X/Z plane). You can use this with AddForce to move in the direction you want:

 Vector3 planeRight = transform.right;
 planeRight.y = 0;
 rigidbody.AddForce(planeRight.normalized * 100);

Comment
Add comment · Show 6 · 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 AndreasX12 · Nov 30, 2013 at 08:06 PM 0
Share

Thanks for your answer.

The reason I'm using AddRelativeForce is, that the Y axis should not be in world Space. When the yaw of the plane is 0, AddForce will work, but as soon as the yaw is for example 90 degrees, the plane will actually move bacwards ins$$anonymous$$d of to the right :)

alt text

avatar image Tomer-Barkan · Nov 30, 2013 at 09:14 PM 0
Share

Well, you wanted it to go left regardless of rotation, and addforce will do that. If you want something different please explain what exactly in more details.

avatar image AndreasX12 · Nov 30, 2013 at 09:23 PM 0
Share

Hehe yeah I see, sorry for being unclear.

What I'm trying to achieve is to make the plane go it's local left/right regardless of the yaw of the plane. At the same time it should be world roll (so that the plane will move horizontal left/right regardless of the plane's roll).

I hope that's easier to understand :)

avatar image Tomer-Barkan · Nov 30, 2013 at 09:45 PM 1
Share

Ok, so if I understand correctly, you want it to go relative left/right, but you want the world Y to always be 0...

If I got it right, this is what I suggest:

Use transform.right to calculate the world direction of your plane's right. Then set the the Y of the result to be 0, and normalize it to be of magnitude 1. Then you have the world direction of your plane's right, but flattened so that the world Y of the vector is 0. You can use this with AddForce to move in the direction you want:

 Vector3 planeRight = transform.right;
 planeRight.y = 0;
 rigidbody.AddForce(planeRight.normalized * 100);

[1]: http://Transform.TransformDirection

avatar image AndreasX12 · Nov 30, 2013 at 11:21 PM 0
Share

Thank you very much :)

I changed rigidbody.AddForce to transform.Translate as it worked better in my case, but the principe was the same :)

Show more comments

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

17 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

Related Questions

World and Local Axis out of Alignment 1 Answer

Cylinder object does not roll as intended 1 Answer

New to Unity: Trying to (loosely) simulate animal flight with separate buttons for each wing... 0 Answers

Is a Rotating World fesable 2 Answers

Rotating an Arrow 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