Raycast and getting groups

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Serenade
:warning: Old Version Published before Godot 3 was released.

Hi!
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 “get_groups.get_name()” 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()
		print(n.get_name())

There it print the colliding Tile Node name~

:bust_in_silhouette: Reply From: kidscancode

Try this:

var n = F_LEG.get_collider()
if n.is_in_group("group_name"):
    print("it's in the group!")

For some reason it doesnt work…

Serenade | 2017-08-24 21:39

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.”

kidscancode | 2017-08-24 22:39

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

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

Serenade | 2017-08-25 06:39

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?

kidscancode | 2017-08-25 06:50

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 get_groups() it shows " root_canvas_112"

Serenade | 2017-08-25 06:54

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! :slight_smile: btw, your lessons rock, haha

Serenade | 2017-08-25 07:06

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

kidscancode | 2017-08-25 13:55

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~

Serenade | 2017-08-25 20:35