Object first time player can walk-though next time blocked

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Oktomol


hope you can understand me.

I have project where i want to have an object/box where the player can walkthough(like no collision) it the first time, but when the player exited the object it will block/set collision. So you can only go though the object the first time, the next time it will be blocked.

i cant not make rigidbody2d and body_exited work.

Do you guys have a better idea


Hi, could you share us some code?

p7f | 2018-12-13 11:31

:bust_in_silhouette: Reply From: Kaizu

If you mean some sort of one way door, I guess you could give the Staticbody/Area2D Collision shape set to “trigger”, and after your Rigidbody exits it, spawn a scene with normal collision shape(or change “trigger” to normal via script, I guess there should be way for it).

:bust_in_silhouette: Reply From: MysteryGM

What I would do is use the collision layers and mask.

The setup would be a invisible wall, on a different layer, that the player first moves past. Then you use a Area node or some kind of event and enable the layer of the wall; now the player can’t pass again.

For more on mask: https://forum.godotengine.org/4010/whats-difference-between-collision-layers-collision-masks

Thank for the fast reply.

Yes that was what i was looking for.

I made a Node2D with a Area2D and RigidBody2D and then change the layer on RigidBody2D when exited the Area2D was exited.

func _on_Area2D_body_exited(body):

Thanks for the help

Oktomol | 2018-12-13 16:12