• 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 RaylaxKai · Jun 10, 2017 at 11:51 PM · rigidbodyfixedupdatemoveposition

Rigidbody MovePosition clipping

When I use Rigidbody.MovePosition and the object being moved hits another Rigidbody, the object will overlap the other slightly until the MovePosition is released (eg, moving the player, if a direction is held "into" a wall, the player will clip into the wall very slightly, then slide back out when the direction is released.

I am using FixedUpdate, Box Colliders and non-kinematic rigidbodies.

 public class MoveController : MonoBehaviour {
 
     public float walkSpeed = 4f;
     public float acceleration = 5f;
     public float deceleration = 20f;
 
     Rigidbody rb;
     float currentSpeed;
     Vector3 movement;
 
     // Use this for initialization
     void Start () {
         rb = GetComponent<Rigidbody>();
     }
     
     // Update is called once per frame
     void FixedUpdate () {
         float moveHorizontal = Input.GetAxisRaw("Horizontal");
         float moveVertical = Input.GetAxisRaw("Vertical");
 
         if (moveHorizontal == 0f && moveVertical == 0f) {
             currentSpeed = Mathf.Lerp(currentSpeed, 0f, deceleration * Time.deltaTime);
         }
         else {
             currentSpeed = Mathf.Lerp(currentSpeed, walkSpeed, acceleration * Time.deltaTime);
         }
 
         movement.Set(moveHorizontal, 0.0f, moveVertical);
         movement = movement.normalized * currentSpeed * Time.deltaTime;
 
         rb.MovePosition(rb.position + movement);
     }
 }

This gif demonstrates the clipping behaviour:

alt text

How do I prevent this? It particularly causes problems when an object in mid-air collides with a wall, it will "stick" to it and stop falling until there is no horizontal push being applied.

Comment
Add comment · Show 11
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 VideoJames · Jun 12, 2017 at 04:18 AM 0
Share

I'm having the same issue described above.

I have a Sphere with a Rigidbody; the Sphere follows the mouse position via Rigidbody.MovePosition.

It works correctly when colliding with another Sphere with a Rigidbody - the second Sphere is pushed around with no overlap. When colliding with unmovable objects it will move inside the object while being pushed back a little, and clip right through if it reaches the center point.

avatar image kornstar83 · Jun 12, 2017 at 04:48 AM 0
Share

have you tried changing the collision detection setting in the RigidBody component to Continuous or Continuous Dynamic? Also try setting Interpolate to "Interpolate" instead of "none"

avatar image hexagonius · Jun 12, 2017 at 10:46 AM 0
Share

MovePosition is used on kinematic Rigidbodies. In your case, change the velocity and the problem will be gone.

avatar image RaylaxKai · Jun 15, 2017 at 08:45 PM 0
Share

@kornstar83 interpolate and collision detection settings don't appear to have any effect on this behaviour

avatar image RaylaxKai · Jun 15, 2017 at 08:47 PM 0
Share

@hexagonius That fixes the overlap issue, but still causes the moving object to stick to walls if it collides in mid-air. The moving object will still clip into the wall for a frame too on collision

avatar image hexagonius RaylaxKai · Jun 16, 2017 at 06:29 AM 1
Share

Are you using continuous collision detection?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Naggiland · Nov 19 at 09:39 PM

use rb.velocity(movement); instead

I think that in most cases its better to not use move position to move a rigidbody.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

10 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

Related Questions

Moving rigidbodies with MovePosition/MoveRotation outside of FixedUpdate 3 Answers

Rigidbody Position Changes don't work when moving. 0 Answers

Rigidbody2d.MovePosition on Update vs FixedUpdate 1 Answer

MovePosition in Rigidbody Ignoring Y axis? 0 Answers

Rigidbody velocity limiter 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges