0 votes

I am working on a game in Godot as a practice, not for selling and I want to detect the collision between a kinematic body and a rigid body. So far so good, the player (kinematic body) can stand on the rigid body, but I don't have a getcolliingbodies function for kinematic body.
Here is the player code:

extends KinematicBody2D

export var viteza = 30
var animNod
var jumped = false

func _ready():
    animNod = get_node("AnimatedSprite")
    set_fixed_process(true)

func _fixed_process(delta):

    #MISCARE

    delta *= 10
    var misc = Vector2(0,1)

    if(Input.is_key_pressed(KEY_D) or Input.is_key_pressed(KEY_RIGHT)):
        misc[0] = 1

    if(Input.is_key_pressed(KEY_A) or Input.is_key_pressed(KEY_LEFT)):
        misc[0] = -1

    misc = misc * (delta * viteza)

    self.move(misc)

    #ANIMATIE

    var newAnim = "idle"

    if(Input.is_key_pressed(KEY_D) or Input.is_key_pressed(KEY_RIGHT) or Input.is_key_pressed(KEY_A) or Input.is_key_pressed(KEY_LEFT)):
        newAnim = "mers"

    if((Input.is_key_pressed(KEY_SPACE) or Input.is_key_pressed(KEY_W)) and not jumped):
        jumped = true
        var hVector = Vector2(0, -1)
        var hSpeed = 2
        var jH = 50
        hVector = hVector * (delta * hSpeed)
        newAnim = "saritura"
        var height = get_pos()[1]
        while get_pos()[1] > height - jH:
            self.move(hVector)

    animNod.play(newAnim)

How to detect collisions between them?

asked Sep 12 in Engine by edimemune (60 points)

1 Answer

+1 vote
Best answer

KinematicBody2D has a method called is_colliding. You can get the collider with get_collider.

answered Sep 12 by quijipixel (510 points)
selected Sep 13 by edimemune
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.