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
0
Question by jzaun · Mar 13, 2016 at 08:34 PM · rotationrigidbodyfreezerotation

Rigidboday fixed rotation not working.

I've got a player GameObject thats a Rigidbody. This has been setup to Freeze Rotation on X and Z.

alt text

If I start bumping into walls the Rigidbody still rotates...

alt text

I event tried to force the issue in script:

 void FixedUpdate () {
     if (!isServer) {
         return;
     }

     Quaternion startRotation = _rigidbody.rotation;

     if (_moveForward) {
         float moveAmount = speed * Time.deltaTime;
         _rigidbody.MovePosition(_rigidbody.position + _rigidbody.transform.forward * moveAmount);
     }

     if (_moveBackward) {
         float moveAmount = (-speed * 0.6f) * Time.deltaTime;
         _rigidbody.MovePosition(_rigidbody.position + _rigidbody.transform.forward * moveAmount);
     }

     if (_turnLeft) {
         Quaternion rotateAmount = Quaternion.Euler(new Vector3(0f, -angularSpeed, 0f) * Time.deltaTime);
         _rigidbody.MoveRotation(_rigidbody.rotation * rotateAmount);
     }

     if (_turnRight) {
         Quaternion rotateAmount = Quaternion.Euler(new Vector3(0f, angularSpeed, 0f) * Time.deltaTime);
         _rigidbody.MoveRotation(_rigidbody.rotation * rotateAmount);
     }

     if (_jump && _isGrounded) {
         _isJumping = true;
     }

     if (_isJumping && jumpTimeLeft > 0) {
         float moveAmount = jumpSpeed * Time.deltaTime;
         _rigidbody.MovePosition(_rigidbody.position + _rigidbody.transform.up * moveAmount);

         jumpTimeLeft -= Time.deltaTime;
     } else if (_isJumping) {
         _isJumping = false;
         jumpTimeLeft = jumpTime;

     }

     if (_shoot) {
         _isShooting = true;
     }

     if (_isShooting && shootTimeLeft == shootTime) {
         GameObject go = ObjectPool.instance.GetObject ("Normal Bullet");
         go.GetComponent<NormalBullet> ().owner = _rigidbody.gameObject;
         shootTimeLeft -= Time.deltaTime;
     } else if (_isShooting && shootTimeLeft > 0) {
         shootTimeLeft -= Time.deltaTime;
     } else if (_isShooting && shootTimeLeft <= 0) {
         _isShooting = false;
         shootTimeLeft = shootTime;
     }

     byte bits = (byte)_rigidbody.constraints;
     Quaternion frozenRotation= new Quaternion(
         (bits & (1 << 4)) != 0 ? startRotation.x : _rigidbody.rotation.x,
         (bits & (1 << 5)) != 0 ? startRotation.y : _rigidbody.rotation.y,
         (bits & (1 << 6)) != 0 ? startRotation.z : _rigidbody.rotation.z,
         _rigidbody.rotation.w
     );
     _rigidbody.rotation = frozenRotation;
 }

How to I freeze the rotation of a GameObject with a Rigidbody on it?

screen-shot-2016-03-13-at-102745-am.png (213.5 kB)
screen-shot-2016-03-13-at-102905-am.png (37.4 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
0

Answer by 5c4r3cr0w · Mar 14, 2016 at 02:05 PM

Well, When you control a rigid body movement with transform, freezing rotation wouldn't help because it simply overwrites physics engine values. Use _rigidbody.velocity instead of _rigidbody.MovePosition and use _rigidbody.angularVelocity instead of _rigidbody.MoveRotation. This will work because it allows the physics engine to controll the constrains you have given to rigidbody.

Hope it helps. :)

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 jzaun · Mar 14, 2016 at 02:57 PM 0
Share

Hi,

$$anonymous$$y understanding is I was using the Physics engine to move because I was using $$anonymous$$ovePosition and $$anonymous$$oveRotation. As far as I know I'm not accessing the GameObject.transform or the Rigidbody.transform directly.

I would like the ship to interact with the physics system but do not want it controlled by the physics system with forces. For example I only want it moving when the keys are pressed.

avatar image Drakonno jzaun · Mar 14, 2016 at 04:14 PM 0
Share

" I would like the ship to interact with the physics system but do not want it controlled by the physics system with forces." - It's perfect example of case, where You want check "Is $$anonymous$$inematic".

$$anonymous$$inematic Rigidbody still can push, move and such on other objects, but other objects can't do the same for $$anonymous$$inematic Rigidbody.

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

52 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

Related Questions

Rigidbody Freezerotation - Freezing one angle? 2 Answers

How do i keep a rigidbody upright? Looking for best way to freeze rotation 1 Answer

How to make the character move and rotate where the camera is facing (3rd person) 0 Answers

Rigidbody Rotation Problem 0 Answers

Rigidbody +parenting +rotation +elevator = Player unwanted behavior(pushed away) 1 Answer


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