Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Large clipping on collision at low speeds

Discussion in 'Physics' started by unity_9uS5llG1WEMwAg, Feb 26, 2019.

  1. unity_9uS5llG1WEMwAg

    unity_9uS5llG1WEMwAg

    Joined:
    Feb 25, 2019
    Posts:
    2
    New project, default settings, version 2018.3.5f1.

    I place a rigidbody and box collider at origin ("character") and a box collider ("wall") 36.39 units away in Z axis. On the character I place the following script:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class CollScript : MonoBehaviour
    4. {
    5.     Rigidbody rb;
    6.  
    7.     void Start()
    8.     {
    9.         rb = this.gameObject.GetComponent<Rigidbody>();
    10.     }
    11.  
    12.     void FixedUpdate()
    13.     {
    14.         rb.AddForce(rb.transform.forward*10*Time.fixedDeltaTime, ForceMode.VelocityChange);
    15.     }
    16. }
    This results in the character clipping 25% of its total length into the wall on the first frame and it takes 4 updates to correct itself to the proper position it should have at impact.



    What can I do to mitigate this?
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,497
    Maybe you're adding an excessive amount of velocity each physics update, so the collision response takes some time to adapt itself to it.

    Also, Time.fixedDeltaTime doesn't make any sense there. You're applying a velocity change, but you're specifying a velocity multiplied by time - that is a distance.
     
    SparrowGS likes this.
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Try making the collision detection continuous dynamic on the object and continuous on the wall.