Search Unity

Question Character controller + rigidbody issue when pushing object

Discussion in 'Physics' started by VascoCorreia, May 8, 2023.

  1. VascoCorreia

    VascoCorreia

    Joined:
    Dec 5, 2020
    Posts:
    23
    Hello everyone!

    In my game, I am using character controllers for the movement without rigidbody. The character is able to push certain objects by clicking a button as shown in the video. This is achieved parenting it to the player, so when he moves it looks like it is pushing the object.
    These pushable objects have a rigidbody component attached, to simulate physics, such as gravity and rotation on slopes.

    The problem I am currently having is that very frequently when I am just running with my character against one of these pushable objects they will get projected, as you can see in the attached video at the 12-second mark and the 34-second mark.
    Besides this if the object is tilted the character is then able to push it too as seen at the 20-second mark.

    I do not know what is happening. But clearly the character controller and the rigidbody are conflicting in some way.
    Does anyone have any suggestions or ideas on what might be happening?

    Thank you!

     
    Last edited: May 8, 2023
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,406
    maybe when the parenting or unparenting happens, maybe the box overlaps the character?

    have you tried other ways for pushing (instead of parenting) ?
    - add force at position
    - using rigibbody character controller and just push with physics (no code)
    - maybe could use joints, then it would allow pulling also
     
    VascoCorreia likes this.
  3. VascoCorreia

    VascoCorreia

    Joined:
    Dec 5, 2020
    Posts:
    23
    Yes, I pretty much think the issue is that sometimes my CC collides with the rigidbody, since my character has no rigidbody its mass is infinite which causes the box to just get ejected! Now this happens much more often after unparenting (releasing the push) but sometimes also happened by just running into the object.

    - I started by using add force at position but realized that I could not do a pushing mechanic with that, or at least I did not knew how so decided to change to my current setup

    -using a RB character controller would mean that I need to change the majority of my movement code I think so I do not think it is a very efficient solution

    -I never worked with joints so I did not know that they can be used to achieve something similar to what I am trying. I will have a look at it thanks!

    Now, I managed to somewhat get around the issue (it sometimes still happens but the object does not get projected just flickers a bit)

    1) added a small cooldown to the pushing/pulling mechanic, since I realized the main times this happened was after the player stopped pushing.

    2) Increase a bit the skin width of my CC

    3) Check on the movable object if he is colliding with the player set
    isKinematic = true;

    And then
    OnCollisionExit
    check again if its the player and set
    isKinematic = false;

    It is not a true fix to the problem but somewhat works

    Not very satisfied but its the best I can do for now. Please if anyone still has suggestions keep them coming