Creating an impassible object

I am trying to create an impassible object (i.e. invisible wall). I have been using a combination of components to the object but I have not found a solution.

I have added ridbodies, and colliders to the wall but the ship object manages to always pass through or simply push it

My ship object is structured like this

player_ship

  • Box collider - IsTrigger not enabled
  • Ridgidbody - IsKinematic enabled
  • Box Collider - isTrigger enabled
  • Rigidbody - nothing enabled
    <Child Obj of player_ship - ship>
  • Sphere collider - IsTrigger enabled

I need to have these things enabled for the various scripts attached to each of these objects.

What would I need to do to create an impassible object for this object?
Thanks.

how are you moving this object, translate or force?

I am moving the ship object with translate

translate can trespass walls, specially when the object is kinematic

youll have to use the correct physics functions if you want it to behave correctly.

any of these… MovePosition/MoveRotation/AddForce/AddTorque

@NoWayMan112 I would suggest to turn off isKinematic on ship. Rigidbody with isKinematic won’t be pushed by collisions.

wont make any difference if the correct move functions arnt used.

To expand on the issue: translating an object simply sets it’s new position. The physics system is not taken into account in any way.

To move using physics, you either add forces to it with the Rigidbody’s AddForce method, or you set the Rigidbody’s velocity directly. The second one is a lot easier to deal with if you’re a beginner, as you can replace your transform.Translate(direction) with rigidbody.velocity = direction.

Also, kinematic rigidbodies will not move by velocity, so make sure to turn that off.

Actually “MovePosition” works great, I tested it out after JamesLeeNZ pointed it out. And it does the job of transform.position

Not quite.

Rigidbody.MovePosition moves the rigidbody to a certain position. If that position is inside a wall, the rigidbody will be pushed out of the wall again through physics.

If that position is on the other side of that wall, though, the rigidbody will teleport through. Unless you have interpolation settings on, the MovePosition method isn’t in any way different from just setting the transform’s position.

Ive never seen a rb push through a collider with moveposition.

Maybe I wasnt using enough force ba-dum-pishhh

1 Like

MovePosition should actually be respecting the wall in 5.x. Might have to use Continuous Dynamic mode, though.

Tried it, it went straight trough. Didn’t even get collision messages.

If you insists on using translate, check with Raycast/SphereCast/CapsuleCast first before translating…