Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Pavel Kotlyar | |
Old Version | Published before Godot 3 was released. |
Hi,
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