- Edited
Hello,
i'm trying to generate a bullet as a variable of a scene, the model is a variable of a weapon, which it self is a variable of my character.
I tried to rubber ducking my code but i didn't manage to address the issue.
extends "res://Personnages/PersoMarcheur.gd"
func init():
$Inventaire.hide()
poid = 75
max_speed =800
max_health =100
accelBotes =600
var sceneArme = preload("res://Armes/poing.tscn")
var Arme = sceneArme.instance()
Arme.set_name("Arme")
add_child(Arme)
func control(delta):
$SuppViseur.look_at(get_global_mouse_position())
velocity=Vector2(0,0)
if (Input.is_action_just_pressed('Sauter')):
accel += Vector2(0,-max_speed*150).rotated(rot)
if Input.is_action_pressed('MGauche'):
velocity = Vector2(-max_speed, 0).rotated(rot)
if Input.is_action_pressed('MDroite'):
velocity = Vector2(max_speed, 0).rotated(rot)
if Input.is_action_just_pressed('Inventaire'):
if $Inventaire.is_visible():
$Inventaire.hide()
else:
$Inventaire.show()
if (Input.is_action_just_pressed('UtiliserArme') and !$Inventaire.is_visible()):
$Arme.tire($SuppViseur/viseur.global_position, $SuppViseur/viseur.global_rotation )`
So this code allow me to call the shoot function when i click. The said function is in the weapon.
`func tire(positionGlobale, rot):
if can_shoot:
can_shoot = false
$TpsRecharge.start()
var dir = Vector2(1, 0).rotated(rot)
if num > 1:
for i in range(num):
var a = -dispersion + i * (2*dispersion)/(num-1)
emit_signal('shoot', balle, positionGlobale, dir.rotated(a))
else:
emit_signal('shoot', balle, positionGlobale, dir)
When the function is called, it emit an signal. I linked the signal 'shoot' to the following function in the scene, which call the generating function of the bullet.
The function is the following.
func start(_position, _direction):
position = _position
rotation = _direction.angle()
velocity = _direction * speed
I'm a bit stuck. Sorry if i was not clear, ask questions if so. Any idea of the reason it doesn't generate anyhting?