Make it so you can't enter an area2d

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

Is it possible to set an area2d as static or something so you can’t enter it? Thanks

don’t think so, why not just put a static body on top of it? what exactly is the context here?

zen3001 | 2021-02-05 16:47

I am making a top down game with a z axis I programmed in, and so if there is a platform, you need to be able to collide with it if you are not above it, however you need to be able to go into it if you are above it, it’s complicated. Luckily I figured it out and now have a working z axis!

djmick | 2021-02-06 01:10

just for the rest of people in that case all you need to do is make the platform a one way collision, you don’t need any area2d for that.

zen3001 | 2021-02-09 14:04

You can’t use a one way collision, as direction actually has nothing to do with it, in fact you need to be able to collide with it from all directions, but also pass through it from all directions. Remember, this is a top down 2d game that I programmed in a z axis for. What I had to do was make all platforms and entities an area. The entities had a ray cast that points in the direction they are moving, and if it collides with a platforms, I make two arrays, one for the entity, one for the platform with every pixel from their base to their top on the z axis by taking their z position through their z position plus their height in pixels, then I intersect the arrays, and if one pixel overlaps and is the same between arrays, they should collide and the entity can’t move forward because it is not over or under the platform, but if the arrays don’t overlap, the entity can move forward, because even though the entities collider would be colliding with the boxes collider, it would be above or below it. Then from there, you have to see if the entity is above or below it, if it is below, it can pass through unless it jumps up to the height of the base of the platform, in which case it must collide because its head would on the top of the platform, but if it is above, it’s z floor, or the distance it falls to must be equal to the platforms base. Sorry that was so long lol, I kind of just started typing and kept going. If you did figure out a way to use one direction platforms for this though, that would be amazing.

djmick | 2021-02-09 23:40

:bust_in_silhouette: Reply From: sinistro25

If you want to prevent a body to enter a region you need to use an StaticBody2D node if the shape is static, or a KinematicBody2D, RigidBody2D if you want the node to move. This will prevent other physics nodes of entering the region.

Yeah I know but for what I was doing I needed areas, not bodies. Thanks for answering though.

djmick | 2021-02-05 19:04