- Edited
Hi, I can not figure out how to make my character have a spike which damages the enemies.
func _on_Player_body_entered(body):
health = health - 50
$Sprite.hide
queue_free()
Hi, I can not figure out how to make my character have a spike which damages the enemies.
func _on_Player_body_entered(body):
health = health - 50
$Sprite.hide
queue_free()
You should probably share more of your code and at least a screenshot of your scene/node tree setup. Ideally a image mock-up showing the concept of what you want to implement would be good too so other forum users get a better idea of what you are going for.
First of all i won't be able to help with such little to know, However you should implement some kind of mechanism to inspect to current player's health, perhaps UI or just print statements is fine, secondly
Can't really determine what object of witch has the Area2D or bieng entered, but since your code indicates that you working on the player's object I'm highly confident that this is just a "syntax error", "syntax errors" have the ability to disable the after code or stop the entire execution flow, and i noticed that you calling $Sprite.hide witch is method and it should be called like this $Sprite.hide(), it doesn't seem that you need it since you freeing the whole player object so remove it and check if you're using $Sprite.hide or any relative mistakes in any other places from you code, and make sure that the signsl is connected properly, try this:
func _on_Player_body_entered(body):
queue_free()
or
func _on_Player_body_entered(body):
body.queue_free()
Sounds like my game. Here's what I have so far. The translucent blue shape is MeleeHitbox. You can use a simple cube to start with. If there are any enemies in the hitbox when you press the attack button, they get hit. Well, being an RPG, they have a chance of getting hit. I don't care if the attack animation actually physically connects with them, as long as they're within striking distance.
And here's the code, simplified to just the relevant bits. The key part is Area3D.get_overlapping_bodies() which gives you every collision body in the hitbox.
func attack_button_pressed():
var thc = 0.25 #TODO weapon.get_base_thc()
thc = remap(get_eff_stat("dex"), 0,10, 0,1.5)
var roll = randf()
var hit = roll <= thc
if !hit:
return
if (...this and that...):
find_child("AnimationPlayer").play("basic_human_animations/punch") #TODO
dmg *= get_eff_stat("str") / 5.0
var area = $model/Area3D
for body in area.get_overlapping_bodies():
if body==self: continue
body.apply_damage(dmg, self)