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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

move dynamic object with kinematic character

Discussion in '2D' started by jonathanmischke, Apr 1, 2020.

  1. jonathanmischke

    jonathanmischke

    Joined:
    Mar 20, 2020
    Posts:
    3
    I'm writing a kinematic character controller and want it to be able to push dynamic objects. But because it stops collisions before they actually happen, my character also stops before it touches the dynamic object and thus is not pushing it.

    Do you have any ideas how to fix that?
    I tried to Google but didn't find anything helpful...
    Thank you.
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    I'm a little confused by this part. If I understand correctly you're saying you detect if you touch another character (which is using a Dynamic Rigidbody2D) and you stop but you want to not stop and continue "pushing" against it?

    If the above is correct then is there a reason why you have to stop when you touch such characters? Can you not use the standard LayerMask in your queries and determine if you've hit such characters as opposed to (say) the Static level geometry?
     
  3. jonathanmischke

    jonathanmischke

    Joined:
    Mar 20, 2020
    Posts:
    3
    Sorry for the confusion I'm not a native speaker.
    So you mean that I should put the dynamic objects on a different layer and ignore collisions for movements on that layer?
    And then the character still collides with the dynamic object, and the physics engine calculates the movement of that object automatically?

    I changed mine now so that if I collide with a dynamic body, I add a force to that body in the opposite normal direction of the contact.
    My character stops, but then is able to start again right away as the dynamic object moves away.
    It works but I'm not sure if that is a "clean" solution.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    I'm simply saying I don't follow what it is you want. Your text above is the only mental image I have of what you're doing, what you expect and and what's not working.
     
  5. jonathanmischke

    jonathanmischke

    Joined:
    Mar 20, 2020
    Posts:
    3
    The kinematic body moves and I use cast, to check the next frame for collision.
    And if the "cast" detects a collision with any collider, I stop the movement so I don't fall through colliders.

    But if I collide with a dynamic body, I'd like to push that body forward and also keep moving forward (a bit slower).

    I hope that is more understandable.
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,623
    It's actually hard to tell you what to do because I only see a part of it. "Move" could mean anything. Whizz away? Move just enough away? Is this a 2D side-view, top-down Also, when you overlap a Dynamic/Kinematic body/collider then the solver will try to move the Dynamic body out of overlap. I have no idea if you want to do this but it doesn't sound like the best way to deal with it so the Dynamic stuff (enemy?) should be set to not collide with the Kinematic if you want to "move" them. This means you can "move" using your own logic.

    Why does it stop? Don't you want to continue moving if you hit Dynamic stuff.

    Honestly, all this text just makes things harder to understand what you want. Maybe some images or a video would help.