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
10
Question by POLYGAMe · Feb 08, 2012 at 07:11 PM · movementtransform.translaterigidbody.moveposition

transform.Translate vs rigidbody.MovePosition?

Okay, here's a REAL noob question for you...

Which of the above should I be using for my race car? It's a VERY basic retro -styled game and I have it working perfectly with transform.Translate/rotate but the collision seems a little odd. I read somewhere that if you want the objects to collide, you should use rigidbody.MovePosition? Is this true? And if so... why is this? Also, I want my game to be able to run on low end hardware... which of the two methods produces the least CPU overheads?

Unfortunately, the Unity scripting reference just didn't answer my questions...

Cheers!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
15
Best Answer

Answer by dannyskim · Feb 08, 2012 at 08:10 PM

The reason why it is recommended to use MovePosition is because when the rigid body is NOT kinematic, an extra step is taken into account when calculating how the rigid body reacts to physics. Since the transform has nothing to do with physics, it is just the coordinate information of the NON physics based components of the Game Object, this causes variation between the two bodies.

Now MovePosition takes this into effect and more properly handles your transform information along with your rigid body information.

When you think about it, when translating the transform and not the rigid body itself in the case of NON-kinematic bodies, the rigid body information is thus calculated at the end of the physics step frame, causing a slight difference in the two positions of each body. It's pretty much the same thing if you translate the position of the rigid body using

 rigidbody.position

or anything of the like. MovePosition was made specifically to deal with this oscillation of the two bodies in conjunction with active physics. CPU overhead is negligible in this case, since MovePosition was made specifically for this purpose.

Comment
Add comment · Show 3 · 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 POLYGAMe · Feb 08, 2012 at 09:59 PM 0
Share

Ah, okay, thanks! So in my case, I can probably get away with transform.Translate, as I don't need physics, so much, just need to change speed when objects touch, as it is a 2.5D game, I am using planes with sprites mapped to them, but have cubes as the collision zones...

Am I right in that thinking?

avatar image dannyskim · Feb 09, 2012 at 12:08 AM 0
Share

Well the slight difference in calculation between the two may provide a chance for the Unity Engine to report inaccurate collisions when recalculating the rigid body's position and collider information. If accurate collisions is your concern, then I would suggest using $$anonymous$$ovePosition as recommended.

avatar image POLYGAMe · Feb 09, 2012 at 12:35 AM 0
Share

Yeah, you're right. I'm finding that with transform.Translate, I can make the trees adjust my car's speed when there is a crash, but then it keeps driving through them. I'm changing the control script now. Thanks for your help!

avatar image
2

Answer by neuropanic · Feb 13, 2012 at 06:35 PM

Sorry guys but isn't rigidbody.MovePosition meant to be used on kinematic rigid bodies? If I well understood the PhysX philosophy, the only way you should move a rigid body is to apply a force.

Comment
Add comment · Show 5 · 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 Jason B · Feb 13, 2012 at 07:14 PM 0
Share

I think you're right, but I've never used $$anonymous$$ovePosition before so there may very well be applications for it outside of kinematics, like if you want something to move but don't want it to be affected by momentum.

avatar image neuropanic · Feb 13, 2012 at 07:31 PM 0
Share

Interesting.. I will try to test the difference! If it's really the case will be really useful for me. Thanks :)

avatar image Owen-Reynolds · Feb 13, 2012 at 08:16 PM 0
Share

Should set force for RBs. And setting velocity directly can handle almost anything, such as momentum & faking friction.

$$anonymous$$ovePosition seems to be for special cases where you know where you want it be be. $$anonymous$$aybe following a motion curve (and blasting things out of the way.) You can set velocity and aim yourself along the tangent, but $$anonymous$$ovePosition is better.

avatar image POLYGAMe · Feb 13, 2012 at 08:33 PM 0
Share

Cool, I'll have a play. I'm still using transform.Translate at the mo, as I found a workaround, but I might try out addforce.

avatar image Agostino · Jun 15, 2014 at 02:41 PM 0
Share

Actually, it looks like it should be affecting object along the way. Quote from the UnityDoc page

Objects lying along the path will be pushed aside if necessary. This often gives a more acceptable result than changing transform.position

avatar image
0

Answer by neuropanic · Feb 13, 2012 at 11:00 PM

Hi Owen, so you already used MovePosition? No issues with complex hierarchy?

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 Owen-Reynolds · Feb 14, 2012 at 01:46 AM 2
Share

I just tested $$anonymous$$ovPos some and decided velocity was better. $$anonymous$$ovPos is glitchy if you stay in contact. Tried these lines, with some child platforms and an unattached RB cube resting on one:

 //rigidbody.$$anonymous$$ovePosition(SS+Vector3.up*Time.time);
 rigidbody.velocity=Vector3.up;

Both move up at a speed of 1$$anonymous$$/S, but $$anonymous$$ovePos makes the cube on top bobble and eventually fall through. Even resting on the parent, I got some bobbling.

avatar image Fattie Owen-Reynolds · Feb 04, 2016 at 09:14 PM 0
Share

Say @OwenReynolds - if you see this ... now that two years have gone by. I have a trivial 2D scene, all objects are Rigidbody2D-$$anonymous$$inematic with CircleCollider2D. No gravity, forces or bouncing, are used at all; I just move the objects in straight lines. I wish to know only when there's a collision between two of 'em

I have tested just ordinary old "Translate" every Update, versus, using this newfangled $$anonymous$$ovePosition.

(Using .velocity is not ideal as the items sometimes don't move in straight lines, they flourish around you know.)

i really can't see any difference at all between Update-Translate and newfangled $$anonymous$$ovePosition .....although, I don't do many 2D projects.

Now that a couple yrs have passed do you a have a handle on this? Which is preferable ... is there kind of a standard approach, or?

Thanks if you know!!

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to get transform.Translate to work with rigidbodies 2 Answers

Trying to stop enemies from clumping together. What am I doing wrong? 2 Answers

Player shaking when colliding with objects 3 Answers

Grid based movement - using transform.translate 3 Answers

Changing speed without changing Destination 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