Search Unity

Question Physics 2D - player and swinging platform - collision without pushing

Discussion in 'Physics' started by Nyriell, Feb 15, 2021.

  1. Nyriell

    Nyriell

    Joined:
    May 22, 2018
    Posts:
    11
    Our game is using physics based movements (scripts modify the rigidbodies' velocities). I'm trying to make a swinging platform attached with ropes to the ceiling and the player should be able to jump on that platform. Any suggestions on how to do that?

    Here is what I tried so far:
    1. Make the platform swing through transform.RotateAround (around the pivot point on the ceiling). Once the player jumps on it, he becomes a child of platform. It worked ok, the player followed the platform, he could run on it, jump off of it but the movement of the platform wasn't realistic as it had constant speed (it wasn't like a pendulum)
    2. Instead of transform.RotateAround, I went with physics to make the movement more realistic. I added a hinge joint and modified the rigidbody's angular velocity. With a bit of tweaking the parameters for angular velocity, angular drag and gravity, the movement looked finally good. However, when the player jumped on the platform he also gave it a push.
    3. Not knowing how else to remove that player's push, I removed the collider from platform and placed it on a new game object that I created as a child of platform. This new game object also got a rigidbody component with body type set to kinematic so it followed the parent's swinging. The swinging movement was fine and the player could jump on the platform without influencing its velocity. The player still becomes a child of the platform once he jumps on it but with physics based movement, he just stays on the same spot and eventually falls down when the platform moves from under him. He follows the platform only if I set his body type to kinematic but then he doesn't move left/right and he doesn't jump (the animations transition correctly but the code doesn't seem to change the player's velocity). Should I set his body type back to dynamic every time a movement btn is pressed while the player is on the platform? And set it to kinematic when no buttons are being pressed? It just seems messy.

    Btw this problem where I want two moving objects to collide without pushing each has been following me throughout this whole project and I keep getting stuck on it and doing some workarounds. Am I missing something obvious?