Trouble getting instanced scenes to communicate
Asked Answered
D

2

0

Following a tutorial that I found by Bitlytic where he used instanced scenes to manage damage, hit detection, and health; I decided to use a similar system (and by similar I mean I copied the bits I like and changed the ones I didn't). Problem is, while the player script tells the weapon script that it needs to execute, the hit is not detected by the hitbox. I know I can use signals in the level to accomplish this but I am loathed to do it this way because of the headache it'd cause me in future. Is there a way?

weapon code

`#sets 3 hitboxes in the attack area to hit
func _get_overlapping_bodies(areas):
targets = areas
if areas.size <= 0:
enemy_in_range = false
if areas.size >= 1:
enemy_in_range = true
target_1 = targets[0]
target_2 = targets[1]
target_3 = targets[2]

#attack handler
func weapon_attack():
print("weapon: attacking")
if enemy_in_range:
var attack = Attack.new()
attack.attack_damage = weapon_attack_damage
attack.knockback_force = weapon_knockback_force
attack.attack_position = get_parent().global_position
target_1.damage(attack)
if target_2:
target_2.damage(attack)
if target_3:
target_3.damage(attack)
print("weapon use")
`

Doe answered 11/11, 2023 at 22:28 Comment(0)
A
0

Your script requires a signal to work.
Create a raycast or raycastshape and check is_colliding on them instead if you don't want to use signals. You check is_colliding in the physics_process.

Aprilette answered 12/11, 2023 at 8:18 Comment(0)
D
0

Aprilette Thank you, this will work. The script is for a melee weapon and now I cant wait to see how badly I mess it up 🙂.

Doe answered 12/11, 2023 at 11:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.