0 votes

i have a kinematickBody2D node, and a staticBody2D, an the staticBody2D hace a grup call "cajaSorpresa", so i want to make something when the kinematickBody2D collide whit the group "cajaSorpresa", for the moment i just want to print something in the console to see that is working correctly. this is the code:

extends KinematicBody2D

export (int) var walk_speed = 200;
export (int) var jump_speed = -420;
export (int) var gravedad = 1200;

var velocidad = Vector2();
var jumping = false;

func get_input():
 #here is the funtion to move the character but idont think that is necesary
#i just use de Input.is_action_pressed and no more

 func _physics_process(delta):
        #here there is a funtion to jump, no necesary put here to the question i think 

        velocidad = move_and_slide(velocidad,Vector2(0,-1));

 #this its the funtion that i can't get it, the game doesn't show any 
#problem when is runing, but either do anything 
func _procesar_colision():
    var collision = move_and_collide(Vector2(0,0));
    if collision.is_in_group("cajaSorpresa"):
        var collidedObject = collision.get_collider()
        print("is colliding whit cajaSorpresa");
in Engine by (22 points)

1 Answer

0 votes

When you do this:

var collision = moveandcollide(Vector2(0,0))

The collision variable will be a KinematicCollision2D object, not the body that you collided with. This object contains info about the collision - more about this here: https://docs.godotengine.org/en/3.2/classes/class_kinematiccollision2d.html

Instead of checking if that is in the group (it isn't), you need to check if the collider is in the group:

if collision.collider.is_in_group()
by (20,485 points)
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.