The problem is pretty straightforward - I need for my enemy node to get the direction signal from the projectile node that just hit him so I could make a kickback in the right direction (need an enemy to be pushed back by projectiles).
For that in the projectile node (that I call prAjectile cause it’s a letter A) I emit a signal:
var speed : int = 400
var doirection : int
signal got_your_ass(doirection)
func _physics_process(delta):
move_local_x (doirection * speed * delta)
func _on_timer_timeout():
queue_free()
func _on_hitbox_body_entered(body):
emit_signal("got_your_ass", doirection)
(I can’t upload a video cause I’m a new user ffs, anyway it doesn’t work because Invalid get index ‘got_your_ass’ on base: ‘null instance’ in the enemy scrips when it tries to connect a signal)
I think, you can do without using signals in this case. In the function func _on_hitbox_body_entered(body): you can get enemy node with your class from body parameter and call he’s enemy_hurt(doirection): function.
Oh I did try that but it gave me the same error as with signals, I believe you can only call the child node’s attributes with this command, but my nodes are not related (well they exist in the same level but are not connected to each other)
So, in any case, you will need to get a projectile using the code. Use signals is not good way at this case. What nodes do you use as a hitbox of projectile and hurtbox_area of enemy?
Still, try to do without signals. Output body to the console (use print()) to see which node got into the hitbox and try to get the enemy out of it. I think body is another Rigidbody, so try to get he’s parent node with your enemy class.
Скажи, пожалуйста, какие у тебя ноды стоят у хитбокса и хартбокса? Я имею ввиду, что при коллизии ты всегда можешь получить объект, который тригернул сигнал body_entered, например, у ноды Area. Только само тело передаваемое в параметр body у сигнала будет RigidBody или другой PhysicsBody. По этому, если скрипт enemy не привязан к ним, тебе нужно получить родительскую ноду, в которой он находится, чтобы получить доступ к функции enemy_hurt(doirection) и вызвать её.
Если вкратце как именно сделать (случайно отправил недописанное):
func _on_hitbox_body_entered(body):
# Я так понимаю, скрипт противника у тебя в родительской ноде
var enemy_node: EnemyClassName = body.get_parent()# Получаем родительскую ноду
enemy_node.enemy_hurt(doirection) # Вызываем функцию из скрипта противника в ней