Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question After collision, object is moving despite rigidbody velocity being 0

Discussion in 'Physics' started by fredetingen, Nov 11, 2022.

  1. fredetingen

    fredetingen

    Joined:
    May 14, 2021
    Posts:
    1
    I have a player who has a rigidbody and box collider, and have obstacales in the game world which also have box colliders. The collisions work fine for the most part, except when I "clip" the corners purposely (for example, walking straight down when the obstacle is below to the right with just a tiny bit of overlap on the right side). Ive included a gif to demonstrate, every time the idle animation plays I am not giving any input, and ive confirmed with debug logs that the rigidbody velocity is 0. You can see that not only am I translating in x and z, but also start moving in y despite never moving in the y direction and also having freeze y position selected (you can see the legs start clipping through the ground)

    This happens regardless of if I move the character by setting rigidbody.velocity or using rigidbody.AddForce, and also regardless of if I give the obstacle its own rigidbody and set to kinmatic, or remove its rigidbody entirely. I am guessing this is a glitch in the physics or some oversight on my part but I am not sure, my understanding of the physics system is fairly shallow. If there is anyone who can help with this, it would be really greatly appreciated!
     

    Attached Files:

  2. AlTheSlacker

    AlTheSlacker

    Joined:
    Jun 12, 2017
    Posts:
    326
    You need to write a simple replicator of your problem. A capsule collider for the player and a cube for your obstacle, resting on a plane. Post your minimum player controller code to replicate (in code tags) and take some screen shots showing how you have the rigidbodies / colliders configured for both the player and obstacle in the inspector. Supply enough information that we can easily replicate the problem ourselves. You should be able to get all of your controller code and input logic in one small c# class.