#Area2D Collision not detecting CharacterBody2D on same layer

66 messages · Page 1 of 1 (latest)

low kindle
#

I've just been doing some tutorials and I'm having an issue with collision layers. I have an "enemy" with an Area2D child node which has it's own child CollisionShape2D, I am also connected to the _on_body_entered signal on the Area2D.

The Area2D has a mask layer of 2 and the CharacterBody2D I am trying to collide with is on layer 2 but I am not seeing any collision with that body's CapsuleShape2D 😦 I am really confused and would appreciate any good docs or help in trying to resolve

bronze thunder
#

If you are just changing its position and not calling move_and_slide() then collisions will not be detected

#

It could also be a problem with the signal connection - can you describe how you did it? Or link the tutorial you are using?

#

In any case if you get completely stuck feel free to upload/share your project and I should be able to pinpoint the problem pretty quickly

low kindle
#

Yup, the enemy (the one trying to make the hit) is also a characterBody2De, I'll post a screenshot:

#

move_and_slide() is being called inside of func _physics_process(delta):

bronze thunder
#

So if the Enemy's Area2D Mask is 2
and the Player's Body Layer is 2
and the signal is connected properly
it should work.

Keep in mind Area2D node has different masks/layers than the body it belongs to

#

Would need more screenshots or the project itself

low kindle
#

Hmmm okay sure, what screenshots can I send?

#

Here's the enemy scene:

#

and here's the player scene:

#

This is the tutorial it's from: https://www.youtube.com/watch?v=43c-Sm5GMbc&t=2s

This quick start guide shows how to handle character movement, animations, tilemap setup, physics collisions, and smooth camera for sidescrolling pixel art games in Godot 4

Download Project ➣ https://ko-fi.com/post/Godot-4--Platformer-Quick-Start-Project-D1D7KPEE4
Also on Patreon ➣ https://www.patreon.com/posts/godot-4-quick-80723131
Art Pack ➣...

▶ Play video
#

but this is technically after the tutorial, I believe the collisions were in part 3. They teach how to make the sword hit the enemy, and I'm trying to do the other way round 😦

#

This is where I did the connection on the area2D

#

I wonder, is it because I have two Collision shape 2Ds on each scene? As I'm not sure how the Area2D is connected to the specific CollisionShape2D? I thought making it the child would be enough?

bronze thunder
#

Each Body and each Area needs its own CollisionShape2D
Enemy's Area CollisionShape2D should be bigger than its Body CollisionShape2D so that it can actually detect things

#

Thanks for the screenshots, unfortunately I don't see any issues and I'm not able to verify the masks/layers

#

Out of time to help right now, good luck

low kindle
#

Hmm here's what the hitbox/hurtbox look like, (the hitbox being the one I want to inflict damage being the larger one outside)

#

I know you're gone for now, but I really appreciate your help! Thanks for coming in SCpray If anyone else sees this, I'm still trying to figure it out Pain

bronze thunder
#

Hi, finished that errand

#

Would you mind zipping up your project folder and sending it to me here or in DM?

low kindle
#

Sure thing!

#

Let me know if there's any issues with the files SCpray

bronze thunder
#

This is usually pretty simple (I doubt you'll run into this in the future)
but it does have a lot of working parts that I feel like I have to poke through to find the issue

#

Thanks, taking a look now!

low kindle
#

Totally understandable, this is my absolute first exposure to Godot, though I'm reasonably good with programming/docs, so like most programming issues, I imagine it'll be a very simple fix PAIN

bronze thunder
#

Head scratcher for sure

#

Everything looks perfect

low kindle
#

Well, a tiny part of me is happy to know it wasn't glaringly obvious haha

#

I wonder if I'm done something incorrect with the connection, that's my biggest suspicion, especially since I can't log any event occuring for the body collision 😦

bronze thunder
#

Yeah somethin' fishy going on, I'll get back to you shortly

low kindle
#

This is incredibly kind of you to give any of your free time to this, I just want to say how much I really appreciate it!

bronze thunder
#

No worries I enjoy it! I've actually learned a lot doing this

#

in general I mean, I hope to have knowledge of all Godot's quirks under my belt

low kindle
#

Makes a lot of sense, best way to learn is to be able to teach someone else

bronze thunder
#

Ok so I noticed Monitoring is false on the Area2D - it does need to be true, so that's currently part of the problem but it still doesn't work when set to true

#

I just made a new Area2D overlapping the whole scene, and it detects bodies.

bronze thunder
#

So if you get rid of that, and then set Monitoring to true on the Snail's Area2D, you should be good

low kindle
#

hmm Are you able to quickly explain what monitoring does? I think I misunderstood that in the tutorial 😓

bronze thunder
#

So, you know how Area2Ds can detect body Bodies and Areas?

Monitorable = I am an Area that can be detected by other areas
Monitoring = I am an Area and actively trying to detect things

#

Area2D will never detect anything if Monitoring is false

low kindle
#

Ahhhh I see, I'm confused because we put that monitoring = false on the sword, but the sword works fine

#

Either way, I can dig in from here to try understand, I appreciate your help so much! Now I need to figure out how to mark this as resolved

bronze thunder
#

gdsalute Glad we got it! Your project and code is very well organized

low kindle
#

That's on the tutorial maker, not me haha

#

but I really liked the state-machine approach, it felt very clean

bronze thunder
#

Best of luck in the future, feel free to DM me whenevs

low kindle
#

Thank you so so much, all the best to you

bronze thunder
#

Oh I'm sorry I missed this part

I'm confused because we put that monitoring = false on the sword, but the sword works fine

#

Let me check into that rq

low kindle
#

I'm guessing it's because the enemys hurtbox is the thing that has monitoring on that?

bronze thunder
#

I think at some point monitoring must be set to true for the sword,
or get_overlapping_bodies() method is used,
But I can't find where

#

Like ... that on_body_entered function should run, even when we aren't pressing attack, right?

#

So why does it only run when we press attack?

#

It appears it's inside one of the animations

#

has a track that changes the sword's monitoring value

low kindle
#

Ahhhhhhh

#

I need to revisit the tutorial

bronze thunder
#

I don't know much about godot's animation system, I'm still trying to figure out how to see those tracks lol

low kindle
#

I had completely forgotten that was added in, my bad 🤐