#Collision Layer (Detection and Check)

1 messages · Page 1 of 1 (latest)

lean tusk
#

I have some problem regaring collisions detection and check

I have walls with layer 1

I have a player layer 32

I have gifts layer 4

And a house with
Chimney layer 5
Roof layer 10

but when I play the game

the gift gets queue almost instantly sometimes (not every time, with the layer print "8")

The walls show layer 1

The chimney shows layer 16

the Roof shows layer 512

How come the layers doesn't show the right number?
And how come there's a random layer 8 interfering?

regal venture
#

If you just want to check if a layer number is enabled or not use get_collision_layer_value(layer) which returns a bool and expect an argument of the layer number (not bitmask)

lean tusk
#

Oh okay, so what I’m doing is not checking the layer used by said object? I will try the other version

regal venture
lean tusk
#

how come there's something colliding with the 8 thing?

regal venture
#

Instead of checking for something vague, you should check what is colliding with the gift

lean tusk
#

or is it just colliding with the players collider? that gives the result of 8?

regal venture
#

I have no idea what your new code looks like or is it still the same

#

Do you know what bitmask is

lean tusk
#

havent done anything major

added _value to the code I already had

regal venture
#

Are you sure? get_collision_layer_value returns a bool so you should never print a number, what does your actual code looks like

lean tusk
#

extends Area2D
@onready var christmasgift: Node2D = $"../.."
@onready var collision_CB: CollisionShape2D = $"../CollisionShape2D"
@onready var collision_A2D: CollisionShape2D = $CollisionShape2D

func _on_body_entered(body: Node2D) -> void:
var layer = body.get_collision_layer()
print(layer)

if layer == 16:
    Global.score = Global.score * 1.2
    christmasgift.queue_free()
    
else:
    Global.score = 0
    christmasgift.queue_free()
regal venture
#

You arent changing anything

lean tusk
#

this. and I put 16 since the collision gave me the 16 value

regal venture
#

The code still exact same

lean tusk
#

yes as of now, yes. I just came back to the computer 🙂

regal venture
#
if body.get_collision_layer_value(16):

else:
#

Thats pretty much all you need to do to check if a body has certain layer enabled

regal venture
lean tusk
#

yes, but I still hade the same error. i will show you

regal venture
#

And? Whats the error?

lean tusk
#

hopefully this works

regal venture
#

Well i am working off very vague context here so you need to be specific what is the intended result and whats actually happening

lean tusk
#

well. the 8 print, shouldn't be there for starters, it collides with what it looks like, the player, and according to the layer/mask config (as seen in pictures), they should not collide at all

regal venture
#

If you mean its still printing same number as before, i already explained it, youre not getting a layer number, youre getting a bitmask, im not explaining it anymore otherwise this is going on a loop.

#

The function doesnt do anything affecting the collision, it just does something after a collision.

A layer is a layer the object its on
Mask is the layer the object searches

lean tusk
#

yes that I know,

and I understand that I'm getting a bitmask (don't know what that is though),
I just need help to make my on_body enter to detect

if it's a wall
if it's a chimney or if it's a roof.
and also ignore the player

i thought it could be done with the body_get_... thing, but apparently that's wrong.

regal venture
lean tusk
#

okay

so I throw out a gift (as seen in the video)
that gift has a Area2D.

and if the gift(area2d) is colliding with the chimney layer, give points
if the gift is colliding with roof layer, remove points
if the gift is colliding with the wall, remove points

#

in other words, if you hit something else than the chimney, loose points.

#

and also, I want to ignore that the gift somehow is colliding with the player

regal venture
#

Okay that gives me more context to understand what you actually wanted to do, give me a moment

#

For starters you should give all of your script a class name. e.g.

class_name Roof extends Area2D

This will be needed to compare if the gifts collide with that type

#

If you have done that let me know and i will tell you the next step

lean tusk
#

so I need to put a script on everything? The chimney for example does not have a script, neither does the roof or the walls

regal venture
#

Yes, even just a one line is fine, because we will need it to compare what we are colliding against

lean tusk
#

okay! so it just need the class and extends?

regal venture
#

Yes

#

Make sure to show me a screenshot of the script and the new setup so i can confirm you did it correctly

#

Keep in mind im about to off so you might want to wait until someone elses showup if i am unable to help later.

lean tusk
#

so I've made a script for the chimney, roof, and walls

added class_name to player(santa) and the gift collider (gift collision)

regal venture
#

And whats the class name of all of them.

#

Remember that in my prespective i dont know what your class name is.

#

Im really about to off so i'll just drop the info now and you'll figure the rest out, on your function for checking body you can now check if youre colliding against that type. e.g.

if body is roof:
elif body is chimney:
elif body is walls:

And so on

lean tusk
#

Oh okay!! Will try this soon 🙂