+1 vote

So im using Raycast2D to detect is the object colliding something and when is, i want it to see does it has a group.. but neither "getgroups.getname()" nor "has("group_name")" works... how can i get the group name.. and also it doesnt see a kinematic body 2D for some reason.. here is my code...

func _fixed_process(delta):

if B_LEG.is_colliding(): # on ground
    if F_LEG.is_colliding():
        var n = F_LEG.get_collider()

There it print the colliding Tile Node name~

in Engine by (227 points)

1 Answer

0 votes
Best answer

Try this:

var n = F_LEG.get_collider()
if n.is_in_group("group_name"):
    print("it's in the group!")
by (21,979 points)
selected by

For some reason it doesnt work..

Maybe if you provided a little more information? An error message, for example? It's very hard to just guess what's wrong from "it doesn't work."

I dont even know where to start.. Heres how it looks...
main scene

Could it be because objects are in different roots, like one is in the main and others are bellow other nodes~?

Wow, you really have a lot of nodes there!

First thing to check: did you check the "Enabled" box on the Raycast2D? It's off by default.

Enable visible collision shapes (click the "antenna" button at the top center of the screen. See if you can see the raycast and other shapes in the right positions.

What are you expecting to collide with? Does the Player have a body + collision shape?

Im not rly sure how to decrease the amount, tiles for background, assets, solid objcts.. I also like to put stuff in containers : D
then containers~
Enabled, both! Everything is in place!
Player has collision (its kinematic), ground(tilemap solid peaces) and enemy obj too. Oh, and when i print getgroups() it shows " rootcanvas_112"

I FOUND THE CAUSE! I didnt know that if objects are in different margins and layers(second layer so that player doesnt collide with throwed objects) that it will not detect anything,, i putted it in same margin, so it works now! Though now ill have to deal with this. I also dont know too well how to use those levels, but ill manage, thank you for help! :) btw, your lessons rock, haha

For example, why do you have a Node2D (PLAYER) to contain your PLAYER instance?

I dunno, it makes me feel its more organised. Previous tests i did, i added Player obj to the scene by pressing button and i kept position2D in a container and just added player obj there.. I have weird ways of doing stuff i guess~

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.