![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | potatoLover |
I was trying to implement a kill feature where player can jump on top of enemies and enemy will die, I first calculated the y co-ordinate of the player and enemy.After that using if statement i checked if player’s y co-ordinate<enemies y co-ordinate then I make the player die.But problem comes when run towards the player it also makes the enemy die. Here is my sample code.
if collision.collider.is_in_group('enemy'):
var player_feet = (position + $CollisionShape2D.shape.extents).y
print(player_feet)
if player_feet < collision.collider.position.y:
print(player_feet)
print(collision.collider.position.y)
collision.collider.take_damage()
velocity.y = -200
else:
hurt()
Is there any other approach to solve this problem or what should i change in my code?