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

(GIF Attached) CharacterController Shouldn't Be Pushing A Rigidbody

Discussion in 'Physics' started by ChiliStudio, Aug 28, 2020.

  1. ChiliStudio

    ChiliStudio

    Joined:
    Jan 19, 2018
    Posts:
    33
    I don't want my CharacterController to push my Rigidbody car.


    I have a player GameObject that uses a CharacterController and a script to control it, nothing else.

    The CharacterController is moved through FixedUpdate with CharacterController.Move(Vector3 motion * time.fixedDeltaTime).

    I have a car that uses WheelColliders, a Rigidbody, and has a MeshCollider.

    When you move and collide into the car from certain angles(the sides especially), it pushes it, like this:


    I have tried
    • All Rigidbody collision detection modes
    • Setting CharacterController.detectCollisions to false
    • Moving my CharacterController in the opposite direction of collisions with Rigidbodys, this didn't work because the car had already been moved before it detected any CharacterController hit.
    • Setting Rigidbody to kinematic won't work because the car uses the physics system to move
    The only other option I know is to Raycast in the direction of potential movement, and to decide whether or not to move based on that, but I would like the player to be able to be able to run against and slide against the car, it just shouldn't be pushing it.

    Please offer any suggestions, thank you.
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    The car's mass likely needs to be much greater than the player's mass.
    Objects with lower mass will require more effort to push objects with higher mass.
     
  3. ChiliStudio

    ChiliStudio

    Joined:
    Jan 19, 2018
    Posts:
    33
    Changing the mass of the car Rigidbody does not help at all, I've even tried insanely high values. Changing the mass of the WheelColliders, on the other hand, has some effect.

    - They are realistically 100 mass, but when I set them to 100000 it is somewhat harder to push the car. But this is not a good solution.

    Unless there is a way to change the mass of the CharacterController, which I've tried to by attaching a Rigidbody and setting it to a low mass, which has no effect. It seems like it doesn't care about collisions, and it is just pushing the Rigidbody outside of the intersection.


    As far as I knew, CharacterControllers by default should not interact with Rigidbodies.


    [EDIT]
    After some testing, I believe it is the WheelColliders that are being pushed by the player, maybe there is a way to disable collisions with them?

    Layer Based collision detection Matrix doesnt change anything either...
     
    Last edited: Aug 28, 2020
  4. ChiliStudio

    ChiliStudio

    Joined:
    Jan 19, 2018
    Posts:
    33
    Well, I've now added Physics.CapsuleCast to test the projected player motion for collisions with the car, and set the motion to zero if it doesn't pass. Feels hacky, and doesn't allow for proper friction.
     
  5. ChiliStudio

    ChiliStudio

    Joined:
    Jan 19, 2018
    Posts:
    33
    SOLUTION: Move charactercontroller.move code to Update!