0 votes

When my player object (kinematic body) is in contact with the barriers I set up (collisionShape2D nodes), it screws up the collision with enemy mobs and stops them from despawning on contact. This is my first project and I have no clue what could be causing this.

This is my collision code on my player node:

var collision_check = move_and_collide(motion * delta)
# Check for collision with enemies
if collision_check != null && collision_check.collider.is_in_group("Targets"):
    take_damage(self, collision_check.collider.contact_damage)

VIdeo of bug

in Engine by (100 points)
recategorized by

2 Answers

0 votes
Best answer

For any interested, added collision check to enemy objects, replaced player movement and collision detection (move and collide) with move and slide. Seems to have fixed all the collision issues i was having.

by (100 points)
0 votes

Make the barriers of type StaticBody2D and add CollisionShape2D as a child to them.

by (381 points)

That didn't solve the issue unfortunately. Forgot to mention that the nodes were children of a rigidbody, testing with a staticbody as a parent didn't change anything.

Oh no, the player is one scene and the barrier is one too. Then you instance them both in one world scene.

Created the barrier in a separate scene and instanced it just now, still didn't work. Same behavior :/

I'm reading through a reddit post, and it sounds like moveandcollide() only returns one of the colliding objects at a time, which could explain what issue i'm having. Trying to find an alternate way of checking for collisions to see if it helps

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.