+1 vote

Here is a link to an video record of the problem (if the gif don't load)
As the title says, when moving my player towards a direction and then another character hit it by behind, the engine seems not detecting that collision.

I move the player with : move_and_slide and both my player and the other character are KinematicBoby type.
Here is the code for detecting the collision for my player :

# Some code to handle inputs
velocity = move_and_slide(velocity)
for index in get_slide_count() :
    collide_data = get_slide_collision(index)
    print(self.name + " collided with " + collide_data.collider.name)

The problem is the same when using move_and_collide :
Here is its code :

collide_data = move_and_collide(computedVelocity * delta)
if collide_data :
    print(self.name + " collided with " + collide_data.collider.name)
Godot version 3.5 stable
in Engine by (26 points)

1 Answer

+1 vote
Best answer

get_slide_collision and move_and_collide return only collisions caused by object itself moving, not if somebody else moves into it. As kinematicbody doesn't react to other objects unless it itself is moving, there's no monitoring for or functions to get other colliding bodies.

The solution is to add area2d around player to react other bodies. Use body_entered signal or get_overlapping_areas() to check.

Another possible solution is to use rigidbody instead, and set mode to MODE_KINEMATIC, which behaves similiarly to kinematicbody. Rigidbody has body_entered signal. You, however, have to implement move_and_slide yourself.

by (810 points)
selected by
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 Frequently asked questions and 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 [email protected] with your username.