Search Unity

Player colliding with moving object

Discussion in 'Physics' started by chevelle_wohr, Sep 18, 2019.

  1. chevelle_wohr

    chevelle_wohr

    Joined:
    Sep 7, 2019
    Posts:
    15
    I've posted this question under scripting already, but I'm not entirely sure its a problem with my script. So just in case I'll post my problem here including my videos that show my problem. I would really appreciate any feedback and help, because I cannot find a solution anywhere to this problem, and I'm hoping its just a box that needs to be checked...
    As you can see in the videos, when I move my player controller to the moving pick up object, my player is pushed downward and out of the map. When I jump on the animated platform I am again pushed out of the area from where I was originally standing.



     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,512
    How are you moving those objects? I have little experience with the Character Controller, but first I'd try to use kinematic rigidbodies in those objects and move them via Rigidbody.MovePosition / Rigidbody.MoveRotation from FixedUpdate.

    Moving the Transform directly (using either transform.position / rotation or transform.Translate / Rotate) just "teleports" the object to its new position, which may cause collision issues.

    Also, ensure the colliders of the moving objects are marked as Convex and assembled properly. In the case of the moving platform, you could use a scaled box for the base, then several scaled box colliders for the handrails.
     
    chevelle_wohr likes this.
  3. chevelle_wohr

    chevelle_wohr

    Joined:
    Sep 7, 2019
    Posts:
    15
    I'm using the animation tool to move the platform up and down. I found the solution with your help. At first I tried to move it with some code like you suggested and adding a rigid-body, but for some reason I couldn't get it to move with the code. So I kept the rigid-body on the parent object and used my animation again with it, and was also sure to check the box 'Is Kinematic'. I did check the boxes for Convex, however I also tested with them unchecked and it seems to be working either way. The problem was me not have a rigid-body at least attached to my parent object, and as you can see in the video I have it working because of your help. I can't thank you enough, this problem has been driving me crazy.
     
    Edy likes this.
  4. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,512
    Glad to help!

    If you're moving the platform via animation then here's a nice workaround to make the animated objects interact physically with others:

    https://forum.unity.com/threads/rig...inematic-rigidbodies-fix.743063/#post-4952462

    I'd definitely give it a try. Despite it's working now, other issues might occur in specific situations (i.e. frames dropped so the platform experiences a sudden movement in one single frame).