Search Unity

Resolved Keep entities grounded

Discussion in 'Physics for ECS' started by PinguIsOP, Aug 6, 2021.

  1. PinguIsOP

    PinguIsOP

    Joined:
    Jul 23, 2018
    Posts:
    16
    I have to groups of entities with non kinematic physics bodies and capsule colliders running into each other. I want them to be able to push each other along the x and z axis but not the y axis. The problem im having is the entities keep getting pushed upwards and end up floating. I have tried messing with gravity but have not found a good value and i have tried manually setting the y position in the translation however that causes unwanted behaviour and entities to clip through the floor and spaz out.

    Is there a way to stop this? What is the best and performant way to keep entities grounded?
     
  2. CookieStealer2

    CookieStealer2

    Joined:
    Jun 25, 2018
    Posts:
    119
    You could try to cancel any velocity in the y-axis each update.
     
    AndrewHerrera1998 likes this.
  3. TWolfram

    TWolfram

    Joined:
    Aug 6, 2017
    Posts:
    75
    Canceling the velocity still causes the objects to get pushed during a collision, they just won't float away anymore. This would work in some use cases probably but I don't think this is what OP was looking for.
    OP, maybe you could try to move the object towards the position you're trying to set the translation value to, but use PhysicsVelocity instead. Pseudocode would be something like velocity.y = ((targetPosition - currentPosition) * deltaTime).y if I'm not mistaken. Would probably still cause some unintended behaviour but would work better than setting the translation for sure
     
  4. PinguIsOP

    PinguIsOP

    Joined:
    Jul 23, 2018
    Posts:
    16
    Thanks for the help guys but neither of those worked for me. Cancelling the velocity didn't seem to do anything and manually setting the y velocity like suggested was part of my initial code(probably should of included the code in the initial post sorry). What ended up working for me is having a system that updates after the fixedstepsimulationgroup and manually set the y translation. Since im only working with flat planes atm this is working fine