Godot Version
Godot 4.2.2
Question
I have a player object and a monster object. I want the monster to be completely intangible, but I want it to be able to hurt the player. How can I detect if the player and monster are intersecting?
Godot 4.2.2
I have a player object and a monster object. I want the monster to be completely intangible, but I want it to be able to hurt the player. How can I detect if the player and monster are intersecting?
You use an area node (Area2D or Area3D) for the monster. Area nodes can detect overlapping physics bodies, but they don’t otherwise interact with them, so the monster will still be intangible.
As far as I know you will need a collision shape of some sort, however, my experience is with 2D.
In the the code for the monster you would have something like:
func _on_body_entered2d(body):
if body.name == "player":
#do some damage
player.health(-10)
Except you would use the 3D version of that. There is also an overlapping bodies function you can use in which case you would use a for loop to go through the bodies to find the player then do the damage.
And don’t have any code like that in the player, that way only the monster can do damage.
HTH.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.