Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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 /
avatar image
1
Question by rjdfhorn2006 · Nov 18, 2011 at 03:13 AM · rigidbodyplatformerfreezeefficiencyside-scrolling

Rigidbody - freeze rotation and position?

Whenever an object has a rigidbody I notice in the Unity editor that you can choose to freeze the rotation (x, y, z) and position (x, y, z) under the Rigidbody Constraints. I'm working on a side-scroller and before discovering this I've been using a short script that "locks" objects onto the z-axis: function Update () { transform.position.z = 0; transform.rotation.x = 0; transform.rotation.y = 0; }

Does anyone know which method is more efficient for hardware? Do they both have the same overhead?

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
1

Answer by aldonaletto · Nov 18, 2011 at 04:04 AM

Rigidbody Constraints only limit physics effects: if you freeze rotations in all axes, for instance, the rigidbody will not rotate when colliding with an obstacle - but you still can rotate it with Transform.Rotate. Freezing the z axis will disallow the rigidbody to be moved by forces or react to collisions in the z axis, but Translate can move it anywhere without any restriction. If this solve your problem, it's cheaper to use constraints - physics must do its job anyway, and constraints probably will reduce a little the time spent managing this rigidbody. But if you don't need a rigidbody, adding it just to have the constraints will be more expensive then using your locking script. By the way, don't set transform.rotation components directly: this property is a quaternion, and its components have nothing to do with the familiar angles we know. These angles can be read and set in the transform.eulerAngles instead:

 function Update(){
     transform.position.z = 0;
     transform.eulerAngles.x = 0;
     transform.eulerAngles.y = 0;
 }
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 warrior · Feb 14, 2012 at 10:43 PM

when you put freeze on in constraints , object freeze when touch other object.

is it possible in code, saying when i put a key unfreeze ?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Object deforms when parenting to a moving platform. 4 Answers

Character Slowly sliding off platform 1 Answer

Velocity Movement & Physics Interactions by Rigidbody2D 0 Answers

How do I make my character jump? 1 Answer

Side scroller - rotate object towards player. 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