Enemy phasing through everything and black rectangle appears randomly [Solved]

Godot Version

Godot 4.2.2

Question

I recently started learning how to make games and I choose my first engine to be Godot. So I picked this tutorial by Brackeys (https://www.youtube.com/watch?v=LOhfqjmasi0) Everything was going great until I started learning to make enemy’s.

First of all when I try to make the enemy move left and right it just goes through the whole map. Lastly sometimes I see a tiny black rectangle appear on top of my enemy for a frame and then disappears.(It also appears when I’m viewing the game scene without actually running the game but the black rectangle doesn’t appear often compared to when I run the game)
I’ve been trying to fix this problem for a while but I honestly have no idea what I’m doing wrong. Any help would be really appreciated, thank you😊

I was going to add a video showing the problem but I can’t since the Godot forums say I’m new user, but you can still view the video through this drive link —> (Help me – Google Drive)

You can also view the project if the video didn’t provide enough detail.

EDIT: Second answer is important

Im not sure about the black bar that appears, but regarding the enemy phasing through the walls: If you want your enemy to collide with walls, it has to be a physicsbody aka a “CharacterBody2D”. But you do the collision-testing with raycasts i guess → you have to make sure the raycast collision_mask has the same layers set as the object its supposed to detect (i assume thats the area2Ds in your level-scene)

I could tell from the video that you mixed up your left/right raycasts. You have to switch the names of the raycasts then the collision should work

You’re right! the raycasts were mixed but it still didn’t seem to fix the collision issue

I just tried making my enemy a characterbody2d but strangely it still continued to phase through everything. I also tried making the layer of my enemy have the same layer as my player and titlemap, I now could collide with the enemy but it was still phasing through my map

Can you tell me what the collisionlayer and the collisionmask of your tilemap is?

both the collision layer and collision mask of my tilemap are 1 and 4

And the collisionmask of the raycast is also set to 1 and/or 4?

yh it is

In your green_slime.gd script you have to use the direction in your movement-method:

position.x += SPEED * delta * direction
1 Like

Thank you so much!!, you fix the problem I forgot to add the direction variable to the movement method😓

1 Like

Turns out that black bar I was talking about was because I didn’t size the sprite sheet correctly. I fixed the problem by adjusting the offset when loading in the frames of my enemy. Got the answer from here (https://www.reddit.com/r/godot/comments/1cmd4vn/weird_black_line_showing_up_when_jumping/)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.