Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by finnrayment · Jan 02, 2018 at 07:51 AM · rotationcollisioncharacter controllerroll

Rotate a rigidbody that has frozen rotation

Hi all. So I've frozen rotation on my RigidBody because I don't want it spinning out of control when colliding with objects at high speeds, but I still want to be able to rotate it myself. When using the freeze checkboxes, it no longer rotates when I use the following code:

 float roll = Input.GetAxis ("Roll") * rollSensitivity * Time.deltaTime * acceleration;
 rb.AddTorque (transform.forward * roll);

My question is, does anybody know a way to make it roll even with the rotation set to frozen, OR, disable rotation from collision? Thanks.

Comment
Add comment · Show 7
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 zero_null · Jan 02, 2018 at 10:13 AM 0
Share

why are you freezing it ? You can alternatively simply get it's rotation restricted to the extent you want ? rb.$$anonymous$$oveRotation($$anonymous$$athf.Clamp(rb.rotation, -45, 45));

avatar image finnrayment zero_null · Jan 03, 2018 at 11:26 AM 0
Share

I can't do that because this is a space game where I can rotate every direction. Clamping it would mean that I can't rotate anywhere.

avatar image finnrayment zero_null · Jan 03, 2018 at 11:27 AM 0
Share

I freeze it so it doesn't rotate on bounce but then if I unfreeze it it rotates on bounce. Freezing it also stops my movements on it.

avatar image Lysander · Jan 03, 2018 at 11:33 AM 0
Share

You could probably just cache your angular velocity every frame ins$$anonymous$$d of freezing anything. In OnCollisionEnter, just overwrite the new angular velocity with the cached copy, and it'll be like the collision didn't happen in that respect only. Defer the overwrite to LateUpdate to be sure that you're overwriting it AFTER it's been changed by the collision though- I'm not sure OnCollisionEnter is guaranteed to fire after the new velocity is calculated.

You'll likely have lingering issues if contact with another object is for more than a single frame, but that should get you closer to a solution at least.

avatar image finnrayment Lysander · Jan 03, 2018 at 11:41 AM 0
Share

Thankyou very much Lysander! I will try this now.

avatar image finnrayment Lysander · Jan 03, 2018 at 11:44 AM 0
Share

Hmm it doesn't seem to do anything. I'm setting a boolean to change in OnCollisionEnter and then replacing it in LateUpdate but still doesn't seem to care about the velocity change.

avatar image Lysander finnrayment · Jan 03, 2018 at 12:16 PM 0
Share

$$anonymous$$ight try delaying it an entire frame- start a coroutine, use WaitForFixedUpdate once (or twice possibly) and overwrite it there. Use Debug.Logs and see if you can pin down exactly where the angular velocity is being recalculated from the collision. This isn't something I've ever had to do before, so I can't really give you much better advice.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by OneCept-Games · Jan 02, 2018 at 11:57 AM

You have conflicting requests. Freezing an objects rotation in one or more axis is taking into account in all Rigidbody physics methods, like AddTorque() etc. In this case, you should rotate your Transform directly by Transform.Rotate(). Doing this, it might cause "bullet" issues with other objects colliding with the object you are rotating by force, so depending on your context, be aware of mixing Rigidbody methods with methods transforming your objects directly - Physics- and Direct transform are not good friends.

Comment
Add comment · Show 2 · 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 finnrayment · Jan 03, 2018 at 11:28 AM 0
Share

I understand but I use the AddTorque() for the express reason of being able to have it happen over time consistently. Using Transform.Rotate() would mean its a one-off rotation.

avatar image finnrayment · Jan 03, 2018 at 11:29 AM 0
Share

It's not a conflicting request per se, rather I simply want to be able to use RigidBody rotations without having any collisions with the environment affect the rotation. I want it to collide, not start spinning everywhere.

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

134 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

Related Questions

Character Controller strange collision bug 2 Answers

How to rotate sphere when moving in Unity 1 Answer

Smoothly Rotate Character Y to Camera Y 2 Answers

Rotate a character controller in the direction of input axis. 3 Answers

How do I both align my character with the normals of a slope AND rotate him in the direction of movement? 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