function is_in_group not picking up on node in group

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ROBOTOO007

here’s my code:

extends KinematicBody2D

var speed: = Vector2(300,300)
var direction: = Vector2(0,0)

func _physics_process(delta: float) → void:
direction = get_direction()
var velocity = speed * direction
velocity = move_and_slide(velocity)
var object_colliding = get_node(“RayCast2D”)
if object_colliding != null && object_colliding.is_in_group(“interractable_objects”) && Input.is_action_pressed(“interract”):
print(“cool”)

func get_direction() → Vector2:
return Vector2(Input.get_action_strength(“right”) - Input.get_action_strength(“left”),
Input.get_action_strength(“down”) - Input.get_action_strength(“up”))

i’ve tested all the other parameters of the if statement that prints out cool and the only one that doesn’t work is the one checking if the object is in the group. I’ve also tried printing it out and all i get is false

I don’t know what to do HELPP!!

:bust_in_silhouette: Reply From: jgodfrey

First, please put code inside code tags so it’s easier to read in the post. To do that, select the code and press the {} button in the post editor’s toolbar…

Looking at your code, your objectcolliding var holds the RayCast2D node itself, not what it collided with…

So, I doubt it’s in the interactableobjects group as you expect. I assume you want to check the object(s) the ray has collided with. You probably want something like:

var ray = getnode("RayCast2D")
if ray.is_colliding():
    var collidedObject = ray.get_collider()
    if collidedObject != null && collidedObject.is_in_group("interractableobjects") && Input.is_action_pressed("interract"):

thanks a lot sorry for not paying more attention and i’ll think of putting my code in brackets for my next post

ROBOTOO007 | 2020-02-26 18:22