I have a wall in my 3D game which is relatively thin and it can be hit on both sides with objects that may occasionally be moving somewhat fast. Is there a reliable way to ensure that the colliding objects will be stopped on either side of the wall as opposed to simply passing through?

  • Xenny@lemmy.world
    link
    fedilink
    arrow-up
    13
    arrow-down
    1
    ·
    edit-2
    1 year ago

    This one is easy

    You just record the position of the object from the last physics tick and raycast from that location towards the objects velocity direction and if the raycast hits a wall you just move the object back to the walls position.

    You usually want to add an additional check like this to all fast moving objects.

    • Rodeo@lemmy.ca
      link
      fedilink
      arrow-up
      6
      ·
      1 year ago

      There is a builtin option in Rigidbody and I think also KinematicBody called continuous collision detection or CCD. It is supposed to do this for you, and with engine code (so much faster because it’s pure C++).

      However I have read some posts here and there saying it doesn’t work properly.