Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Tritize · Apr 26, 2020 at 10:59 AM · rotationupdatefixedupdateaddtorque

Apply a rotation AND a torque at the same time ?

Hi, I have an issue since a while now.


My player have a rigidbody. I'm making him lookaround with the mouse and transform.Rotate(). And in my game there is an event that apply a torque with rigidbody.addTorque that make the player rotate. In the editor updates and fixedUpdates are synchronized and both can be applied at the same time, works fine.


But when I build, Updates are way faster than fixedUpdates. So when I try to apply both at the same time the transform.Rotate() 'overwrite' the addTorque. I tried a coroutine 'waitForFixedUpdate' for the Rotate(), now both work at the same time in the build, but when I look around with the Rotate() it's jittering, not smooth at all. Anyone could help me please?

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
0

Answer by streeetwalker · Apr 26, 2020 at 02:02 PM

@Tritize, It's not exactly clear in your post but If you are using Righdbody Physics do not also attempt to manipulate the transform properties of the object

Note that all input code must go into an Update event handler to work properly and always use FixedUpdate for physics related code for it to work properly.

You may Use and of Rigidbody rotation methods to try to rotate an object to look at something

Another way is add your object as a child of the Rigidbody - that is, apply a Rigidbody to the an empty game object and give it a collider. Remove the Rigidbody and collider from your game object and add it as a child of the empty parent Rigidbody object. You can then freely and rotate child transform without any conflict.

You can try to synchronize Update and FixedUpdate, but you have to be aware of how much your code is trying to do with physics. I recommend reading this article: https://johnaustin.io/articles/2019/fix-your-unity-timestep

Comment
Add comment · Show 8 · 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 Tritize · Apr 26, 2020 at 02:39 PM 0
Share

I am using rigidbody physics for everything except to orient the view of the player. It's an FPS and I'm using rigidbody.transform.Rotate() to make the player look at where I point with the mouse. And that's what is causing a conflict with an addTorque. So if I don't use the transform.Rotate() like you suggest I have to orient the view of the player using Torques ? Seems difficult to achieve, how should I do this ? :/

avatar image streeetwalker Tritize · Apr 26, 2020 at 02:51 PM 0
Share

@Tritize, It wasn't clear in your explanation if the code was already applying another torque to get the Rigidbody to move. If you are then it would seem the only way to independently look at a target is to use the alternate method I wrote about

If you are not applying a torque for motion, then you don't have to apply torque to rotate an object.

You can use Rigidbody.rotate and Rigidbody.$$anonymous$$oveRotation to set rotation values directly. If you have used Rigidbody.AddForce or some other Rigidbody method to move your object, setting the rotation directly through those functions will not affect the motion as long as the center of gravity (center of mass) is in the center of the object.

(if you have some odd shaped mesh collider on the object, that may be a consideration, as the collider defines the volume of the physics mass and center of gravity may not be what it seems. You'd have to try it!)

avatar image Tritize streeetwalker · Apr 26, 2020 at 03:03 PM 0
Share

$$anonymous$$y mesh collider is a simple sphere. Yes I'm applying a torque with my code. Which is the alternate method in your previous post?

edit : put a child that is affected by torque while parent is affected by transform.Rotate() ?

Show more comments
avatar image Tritize · Apr 26, 2020 at 05:15 PM 0
Share

Ok I tried your alternative way. I have the parent with rigidbody and the child that I transform.rotate.

Problem is, when I apply a torque to the parent, I don't have the same behavior than before at all. $$anonymous$$aybe it's because the rigidbody axis are not aligned anymore with the ones of the child? And even by adding a torque on the rigidbody like addTorque(child.transform.forward...) it does a rotation without any sense...


Yeah when I do addTorque(child.transform.forward) the rigidbody rotate around its own forward.. and since its not aligned it does nonsense. Any idea how to correct this ?

avatar image streeetwalker Tritize · Apr 26, 2020 at 05:21 PM 0
Share

First, you must not have a Rigidbody or collider on the child - it will cause trouble. You have to be specific about the behavior. Yes, you would need to make sure your object is centered. But if the child does not have a rigid body or collider it will not affect the behavior of the parent rigidbody in any way other than visually if the child is not centered.

I don't quite understand why you are applying a torque force to move the object if you don't want it to look like it is rotating. You want the object to point to the mouse? Then don't use torque to move it. Just AddForce in the direction you want to move. If it's rolling on the ground or against some other object, just remove any angular drag and friction. It will slide with AddForce, and you can use RigidBody.rotate to point where ever you want.

avatar image Tritize streeetwalker · Apr 26, 2020 at 05:27 PM 0
Share

I don't have any collider or rb on the child. child is centered to the parent. But when I apply a torque to the parent, axis of the parent and of the child does not match (I test that with a simple sphere atm).

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

241 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 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

Optimizations: Should I use Update or FixedUpdate? Could you help me optimize rotations? 1 Answer

Score, FixedUpdate and Update 0 Answers

Only Disable One Update on a Script 1 Answer

GetKeyUp fires on too many frames 3 Answers

HoverBike rotation return Y axis to 0 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