• 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
1
Question by saxenasiddhant12 · Mar 04, 2019 at 08:47 AM · rotationmovementphysics

Quadcopter moving downward because of tilting. How to make it move without changing y axis velocity when presing WASD?

I have created basic movement for a drone using addRelativeForce with WASD input for movement in 4 directions and Spacebar to go up and leftcontrol to go down. I have added tilt when the quad moves. When i move in any of the 4 directions, because of the tilt the drone starts moving downward. I want the drone to ignore any rotation around x and z axis w$$anonymous$$le adding force and only consider rotation around y axis because that will be used to rotate(swivel) my drone left and right. Im using Vector3.up, Vector3.forward, Vector3.right with the addRelativeForce function along with appropriate multipliers that control the speed. How do i approach t$$anonymous$$s situation?

Comment
Add comment · Show 5
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 xxmariofer · Mar 04, 2019 at 09:07 AM 0
Share
avatar image saxenasiddhant12 xxmariofer · Mar 04, 2019 at 09:13 AM 0
Share
avatar image xxmariofer saxenasiddhant12 · Mar 04, 2019 at 09:46 AM 1
Share
Show more comments
Show more comments

3 Replies

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

Answer by xxmariofer · Mar 04, 2019 at 10:25 AM

the relative force adds a force relative tothe rotation, so i got the negative of the object rotation for "fixing" the tilt direction. t$$anonymous$$s code is assumming the helicopter is only tilted in one axis (tested in the x axis). i am not that good at vector maths so i cant t$$anonymous$$nk of a solution for all use cases. code example:

 void Update () {
     Vector3 vector = transform.forward;

     GetComponent<Rigidbody>().AddRelativeForce(new Vector3(vector.x, -vector.y, vector.z));//t$$anonymous$$ss code asumes the object is rotated in the X axis.
 }
Comment
Add comment · Show 4 · 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 saxenasiddhant12 · Mar 04, 2019 at 10:32 AM 0
Share
avatar image saxenasiddhant12 · Mar 04, 2019 at 12:30 PM 0
Share
avatar image xxmariofer saxenasiddhant12 · Mar 04, 2019 at 12:34 PM 0
Share
avatar image saxenasiddhant12 xxmariofer · Mar 09, 2019 at 07:58 AM 0
Share
avatar image
1

Answer by WarmedxMints · Mar 04, 2019 at 09:44 AM

AddRelavtive force, as the name suggests, applies your vector force relative to the Rigidbody's directions. So when it is tilted, its forward, back.left.right directions will either be pointing up or down. Try using AddForce or AddForceAtPosition instead.

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
avatar image
1

Answer by saxenasiddhant12 · Mar 04, 2019 at 10:24 AM

@WarmedxMints but i need to consider rotation around y axis w$$anonymous$$le moving as the quadcopter will be swivelling(rotating) around y axis when we move the mouse thats why im using addRelativeForce. So maybe as @xxmariofer suggested i should just add the z component of force and let the other 2 be zero. Then it will ignore the x and y component of the transform and move only in z direction.

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 xxmariofer · Mar 04, 2019 at 10:33 AM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

218 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

Related Questions

How not to make a RigidBody not go into ground when tilted foward? 1 Answer

How to make a RigidBody not go into ground when tilted foward? 2 Answers

Update speed and physics makes my rigidbody jiggle 2 Answers

Character still walking when no key is already pressed 1 Answer

Prevent Rigidbody From Rotating 3 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