Topic was automatically imported from the old Question2Answer platform.
Asked By
Godot_Starter
I have a Sword (it is attached to a Player) which moves if I press Space. And I have a Enemy (KinematicBody2D). How can I change the health variable of the Enemy, when the Sword enters the Body of the Enemy? The problem is, that the sword is the same body like the Player so I cant different between them actually. How can I solve this?
Create an Area2D to animate with/parent to the sword and connect the body_entered signal. The body_entered signal has the parameter body which will reference the intersecting body i.e. the enemy, and the health variable can be accessed directly through that - body.health
Take note if you animate the Area2D make sure to set the AnimationPlayer’s playback_process_mode to ANIMATION_PROCESS_PHYSICS.