0 votes

here's my code:

extends KinematicBody2D

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

func physicsprocess(delta: float) -> void:
direction = getdirection()
var velocity = speed * direction
velocity = move
var object
colliding = getnode("RayCast2D")
if object
colliding != null && objectcolliding.isingroup("interractableobjects") && Input.isactionpressed("interract"):

func getdirection() -> Vector2:
return Vector2(Input.get
actionstrength("right") - Input.getactionstrength("left"),
actionstrength("down") - Input.getaction_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!!

in Engine by (120 points)

1 Answer

+1 vote

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"):
by (10,856 points)

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

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 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 webmaster@godotengine.org with your username.