Search Unity

Transform.Translate / Rigidbody.MovePosition Collision issues 2020.1. Fixed Update

Discussion in 'Physics' started by toomasio, Nov 9, 2020.

  1. toomasio

    toomasio

    Joined:
    Nov 19, 2013
    Posts:
    199
    I am getting tons of students coming to me saying that the physics are not working correctly on their controllers when using 2020.1.

    I ran a quick test and it seems transform.Translate and Rigidbody.MovePosition in Fixed Update are not behaving how they used to. Any speed above 10m/second (which is pretty slow), causes colliders to slip through each other. It seems like Fixed Update is not behaving the way it should.

    I have resorted to using Addforce and playing with the drag settings for now...but this seems very odd to me. Anyone else having these issues in 2020? I went through all the rigidbody collision detection settings as well and they all have the exact same result.

    colliderissue.gif
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class Move : MonoBehaviour
    4. {
    5.     public float speed;
    6.     private Rigidbody rb;
    7.  
    8.     private void Awake()
    9.     {
    10.         rb = GetComponent<Rigidbody>();
    11.     }
    12.  
    13.     private void FixedUpdate()
    14.     {
    15.         transform.Translate(Vector3.forward * speed * Time.deltaTime);
    16.         //rb.MovePosition(transform.position + Vector3.forward * speed * Time.deltaTime);
    17.     }
    18. }
    I ran the exact same environment in 2019 and it behaved fine. Any help is appreciated thanks!
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Neither Transform.Translate or Rigidbody.MovePosition handle collisions, in any Unity version. These methods cause an instant "teleport" of the Rigidbody to the target position. When the rigidbody is suddenly teleported to a position colliding with another collider, the physics engine has to resolve the collision somehow.

    The different behaviors between different Unity versions are coincidental, possibly because of new/deprecated physics options, or existing physics options changing their default value. But using Translate or MovePosition in that way is no guarantee of collisions being handled correctly by the physics engine.

    The correct way of moving rigidbodies and having the physics engine resolving collisions properly is using Rigidbody.AddForce (and/or its variants). This methods has several options to impose velocity changes or accelerations instead of pure forces. In all these options the collisions are resolved in a physically correct way in all Unity versions.
     
  3. toomasio

    toomasio

    Joined:
    Nov 19, 2013
    Posts:
    199
    Thanks for the explanation @Edy . Translate and MovePosition were fairly reliable with my projects up to this point. Guess I need to switch to Addforce. Also looks like a ton of tutorials for character movement will also be obsolete.

    Would you happen to know the best way to make snappy movement controls that work properly with physics? Something as close to teleporting as possible...Or is it just playing with the drag settings and movement power?