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 TheSaviour · May 20, 2017 at 08:46 AM · physicsrigidbodybug-perhapsmoveposition

Rigidbody.MovePosition not behaving as expected (possible bug?)

My scene is simple. There's a cube with a Rigid Body component attached. Here's all the info on it's Rigid Body component (from the inspector):

 Mass = 1
 Drag = 0
 Angular Drag = 0.05
 Use Gravity = (False)
 IsKinematic = (True)
 Interpolate = Interpolate
 Collision Detection = Discrete
 No Constraints

There's another cube in the scene without a Rigid body. This cube will simply act as a destination point for the first cube.

I want the first cube to smoothly move towards the destination cube's position using the Rigidbody.MovePosition function. Here's the code I used on the first cube:

 public class CubeMotion : MonoBehaviour 
 {
 
     private Rigidbody rb;
 
     public float speed;
     public Transform destinationPoint;
 
 
     void Start () 
     {
         rb = GetComponent<Rigidbody> ();
     }
 
     void FixedUpdate () 
     {
         rb.MovePosition (destinationPoint.position * Time.fixedDeltaTime * speed);
     }
         
 }

However, the cube doesn't move to it's destination point as expected. It simply teleports to it's destination point. I even tried changing the destinationPoint variable from a Transform to a Vector3 (as the manual suggests):

 private Rigidbody rb;

 public float speed;
 public Transform des;
 public Vector3 destinationPoint;


 void Start () 
 {
     rb = GetComponent<Rigidbody> ();
 }

 void FixedUpdate () 
 {
     destinationPoint = des.position;
     rb.MovePosition (destinationPoint * Time.fixedDeltaTime * speed);
 }
     

Since the destination cube is located at coordinates 0,0,0, I even tried this:

 rb.MovePosition (new Vector3(0,0,0) * Time.fixedDeltaTime * speed);

None of them worked. I even tried playing around with the main cube's Rigid body values (like setting IsKinematic to "false" and setting Interpolate to "none"). They all lead to the same result: The first cube simply teleporting to the position of the destination cube, instead of the smooth transition I was expecting. I know I can achieve better results by using Vector3.MoveTowards() function, but I'm not going to do that. I want the cube's movement to be entirely based on physics (hence Rigidbody functions).

So, am I doing something wrong? Or could this be a bug in Unity? I'm using Unity version 5.5.1 (64-bit) .

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
2

Answer by GrogmanEsquire · Jun 08, 2018 at 05:54 PM

 Vector3 direction = (destinationPoint - transform.position).normalized;
 rb.MovePosition(transform.position + direction * speed * Time.deltaTime);

This is what you want to do, rather than input the destination coordinates, you want to input the current coordinates with the addition of a directional vector. you can use a Speed float to alter the magnitude of your directional vector.

the way MovePosition() works, when it is called it moves the rigidbody from where it is, to the Vector3 that is fed into it. so inputting the final destination directly and multiplying it, immediately teleports the rigidbody to that position. in order to have it step over time, every fixedupdate you want to poll the current position, and move along a directional vector toward the destination. so for example if every fixedupdate you wanted to move your rigidbody left, you would want to add a vector (-1,0,0) then you would modify that by your speed and time variables to control the rate each fixedupdate.

rb.MovePosition((transform.position + new Vector3(-1, 0, 0)) * speed * Time.deltaTime);

every FixedUpdate it would move the object -1*speed*time.deltatime from its current position.

I know this is a bit of a necro on an old question but figured I'd put up the answer just in case someone else stumbled across it.

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

114 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

Related Questions

Rigidbody.MovePosition/MoveRotation Hits far away colliders 2 Answers

Calling Rigidbody.MovePosition, no movement at all 4 Answers

My Player goes through the colliders even I used Rigidbody.MovePosition , Please help me !! 2 Answers

Is it possible to prevent parent rigidbody physics from effecting children rigidbodies? 1 Answer

Freeze Rotation constraints doesn't work. 2 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