Tilemap Collision vs Static Body Collision

Godot Version

4.3

Question

Alright so i am making a space adventure shooter and i’ve come across an interesting problem. I have a player with WASD tank style movement and rotation and an enemy that persues the player which has a static body collision with its scale being animated to create a knockback effect.

The issues is when being pushed by the enemies static body the player tends to phase through the Tilemap collision shapes and gets stuck . Ive found that adding a static body rectangle shape over the Tilemap area seems to keep the player from getting stuck but is this really the answer…??? any help is appreciated.

1 Like

You can add a picture or video by pressing the up load button near the text box or by dragging and dropping. If your in windows you can take a screenshot for a section of your screen with shift-window-s (Or something along those lines) or if your in Mac shift-command-5 where you can take a photo or screen recording but you have to convert the screen recording from MOV to mp4

Thank you for the info, yeah when i click upload it pops up saying “sorry new users cant upload attachments”… it only lets me upload 1 photo. I will add that i am on a tablet with mouse and keyboard so idk.

Anyways so i’ve uploaded a photo with red edit marks one is where the player gets stuck and the other is where i’ve had the player stuck in a previous play.

If you don’t find a way to fix this easily there are 2 ways I would think could work. 1 would be just to put those static bodies everywhere but that’s annoying and there is probably a better way. 2 is maybe just making a script to return anything that finds its way inside the walls back to a position but that’s just annoying.

I would try to check the settings of the tilemaps and seeing if you forgot to enable or accidentally enabled anything there.

1 Like

I’d show the code you’re using for the collisions. Are you doing move_and_slide, some custom physics, applying forces, etc.

You might also try using an AnimatableBody2d. Double checking the documentation, a StaticBody might wind up with your player being overlapped by 2 static (unmoveable) bodies, thus being forced to clip into one or the other as neither will respond to the physics engine on its own.

1 Like

Im actually using an AnimationPlayer to adjust the scale of the collision object that pushes the player in pair with an Areabody2D to trigger the animation.


Here is my Tileset. All i’ve done is painted physics layer 0 for each piece and shaped them accordingly. Beyond that nothing else is checked or altered.

Have you tried using different physic bodies to see if they interact with the tiles as well?

So as far as collision layers go, for my Tilemap this is the list.

1 is Player, 5 is Enemies and 6 is Enviornment.

One thing i did try doing is adding more tiles to beef up that small spot where corners meet but alas this was the result…( next post for photo)

Hard to see the player in the photo but its stuck closer to the middle of the collision shapes.

Hmmm I’m not sure but maybe @wchc can help because im stumped and he is really smart

1 Like

I’ll continue to fiddle around thank you so much for responding to me.

1 Like

Sorry I couldn’t help more

Hey, I know this is kinda old but I wanted to pop in and see if I can help.

The description of StaticBody2D is:

A 2D physics body that can’t be moved by external forces. When moved manually, it doesn’t affect other bodies in its path.

So changing properties on the StaticBody2D of the enemy doesn’t sound like it’ll do what you want to the player body.

It sounds like what you want is for the player to get bounced away from the enemy on collision. It might be better to change the enemy so it has an Area2D on it. You could set up a signal on the body_entered for the enemy that adds a force to the player?

You also wouldn’t have to add static bodies to the tilemap – a regular physics layer painted on the tilemap would be enough (if your player is a CharacterBody2D).

That way you’re not messing around with the physics engine trying to get it to do what you want, you’re coding the behavior of what happens to the player and separating that from the graphical effect of the enemy sprite getting bigger?

hey thank you so much for the response so yeah your right an Area2D is more effective. I had created a laserbeam that functions in the same way but coding it is a bit of a hassle.

So here is the laserbeam with an Area2D with a signal (on body entered & exited).

when the player enters the body the signal triggers a global variable to activate to force.

Here is the code for applying the force. While this does “work” the force feels really spongy instead of a more instant quick force and the higher force value i give it the further back the player is pushed (also not desireable but it works for the laserbeams for now). And the annoying part is for it all to work correctly i have to have a seperate scene with seperate scripts in order for each beam to have it’s “own force”, otherwise the force is based off of one beam and its creates an odd result. I’ll keep fiddling with it.