0 votes


I have a KinematicBody2D "Player" and KinematicBody2D "Enemy". The Player can move in all directions and controlled by a keyboard, and the Enemy can move from left to right and controlled by 'AI'. Both are squares with CollisionShape2D attached properly.

Now, the strange behaviour is: when in _fixed_process in "Player" script I check if is_colliding(): it works well all the time except when the Player is colliding with the Enemy from left side of Enemy's square or right side, if the Player is colliding from the top or bottom of the enemy square - it is triggering. The way how I "fixed" the issue is moved is_colliding(): check from the "Player" script to "Enemy" script and suddenly it started to work as expected - colliding is triggering all the time when the Player is colliding with the Enemy does not matter left, right, top of bottom of it...

While the issue was "fixed", I am not sure why at the first place I had this issue? Just want to understand the reason behind of it... Maybe it is somehow related to the Enemy's direction (left, or right only) but still don't understand why moving is_colliding(): to Enemy script resolve the issue? (I think btw it is a good place where this logic actually should be but, just want to know why it did not work in Player script)

Here is the "Player" code https://github.com/paxer/marine_treasure_hunter/blob/master/scenes/main/player.gd#L49 from where I moved "is_colliding" to "Enemy" script for a reference https://github.com/paxer/marine_treasure_hunter/blob/master/scenes/enemies/enemy.gd#L31

in Engine by (80 points)

2 Answers

+1 vote
Best answer
is_colliding() works only when the player/enemy is moving. So Player can also detect collision but only if it's moving at the time of collision 
by (528 points)
selected by

ahh! thanks!

0 votes

I'm not sure, but maybe, in the physics process, the server separates the player from the enemy, making the enemy not able to collide with the player.

What you should do is to separate the layers, if you don't want the player to collide with the enemy, don't put the enemy mask, and if the enemy should ignore items, add the mask where the player layer is and don't add the items, each on his own layer, of course.

If items can be collected, maybe is better to make areas from them and let them react on the "body_enter", by affecting the player or something else (like a score object), or, if items are too many to manage that way, add an area to the player that can be used to detect other areas and do the actions it need, filtering by groups or types.

by (7,900 points)

thanks for advice about Area, will try this approach too!

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.