Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | antigo |
hi
so i have a mob logic, and when it is initially facing the player it follows it just fine and successfully collides. however when the player hops over the mob it still follows it but stops at a safe distance from the player therefore not damaging it.
here’s the code:
#player detection logic, ideally if it works func _on_Area2D_body_entered(body): if player == body: detected = true func _on_Area2D_body_exited(body): detected = null #function for animations and player detection logic func animations_and_detection(): velocity = Vector2.ZERO if detected: playerpos = player.global_position Vector2(0,0) velocity = position.direction_to(playerpos).normalized() * minSpeed else: animation.play("idle") if velocity.x > 0: get_node("AnimatedSprite").flip_h = true else: get_node("AnimatedSprite").flip_h = false func _physics_process(delta): animations_and_detection() velocity.y = gravity * delta velocity = move_and_slide(velocity, Vector2(0, -1))
pictures for better understanding of what happens:
the (more or less) intended way on the mob’s face:
Imgur: The magic of the Internet
my problem on the opposite face:
Imgur: The magic of the Internet