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 Shifty-Geezer · Jun 27, 2013 at 11:30 PM · rotationrigidbody

How to rotate gameobject and rigidbody?

I have a 2D game using physics. I want to manually control rotation and have the rigidbody apply only movement. I have used transform.Rotate to rotate the object, and rigidbody.AddForce(transform.right*power); to apply a thrust. However, this provides a thrust only in the one direction, and doesn't match the direction the object is facing (based on my transform.Rotate).

How do I synchronise rigidbody direction, or force direction, with my gameobject rotation? Thanks!

Edit: Scrap this! It was my fault. My code for limiting top speed was messing it up.

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 golden pouria · Jun 27, 2013 at 11:59 PM

Please remember that when the rigidbody.AddForce(Direction * power) function is called, the object will be forced to moved towards the Direction that it is in, at the point that you call the AddForce function. So you call the function only once, and therefore, you pass the direction only once. Regardless of how many times the object rotates.

(in the real world, imagine a basketball, when you throw it, it rotates in the air 3000 times, but that doesn't change the direction of it. The ball moves ONLY towards the direction that you forced it at the time of throwing...)

One of the solutions is that every now and then check the status of the Rotation, and if it is different, stop the object (Neutralize the force) and then call the AddForce again (this time with the new rotation direction) and repeat this process again and again.

Hope this helps.

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
0

Answer by robertbu · Jun 28, 2013 at 03:31 AM

By default, Unity's physics engine mimics real physics. Imagine a space ship flying in a certain direction. If you apply thrust to the side of the ship, the ship does not immediately turn 90 degrees. There are a couple of approaches you can use if you are looking for faster turn based on applying force in a new direction. The first is to up the 'Drag' in the rigidbody. 'Drag' is 0 by default. This will cause existing velocity to decay more rapidly so that the new force will take hold faster. If you are looking for an immediate turn you can do something like this in FixedUpdate():

 rigidbody.velocity = transform.forward * rigidbody.velocity.magnitude;

This takes makes the ship fly at the existing velocity in whatever direction transform.forward is facing.

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

16 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

Related Questions

Add Force to the right of the rigidbody, not right of the screen 1 Answer

Can i Move/Rotate triggers without Rigidbodies? And other collider questions. 3 Answers

Pysics not working as expected 1 Answer

Oculus VR Wrist Rotation Relative to Arm 0 Answers

Objects Instantiating at wrong position 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