0 votes

Hello, i'm coding a basic game.
My problem is the following: on one hand, long ranged weapon works wells. I have followed this tutorial, and everything i get from here is on point. (link of said tutorial: http://kidscancode.org/blog/2018/04/godot3_tanks_part1/)
On the other, close combat weapon do not produce anything.

What i did:

if ($ArmeEquipee.cac):
        var b = $ArmeEquipee.balle.instance()
        self.add_child(b)
        b.start(positionGlobale, dir)
    else:
        emit_signal('shoot', $ArmeEquipee.balle, positionGlobale, dir)

So, this is the code used when any character attack. The signal is linked to the main scene were the following piece of code generate my bullet!

func _gen_projo(bullet, _position, _direction):
    var b = bullet.instance()
    add_child(b)
    b.start(_position, _direction)

To precise what is a weapon in my code: it is just a bunch of variable that will fixe the rate of fire, the scattering, the type of bullet used and if it's a CC weapon or a long range one. The code that "shoot" is written above, in the caracter.
Lastly, i tried to consider a CC weapon, as a long range one, and it works. (cac = true, for CC weapon, false for LR)

extends Node2D
var can_shoot = true

var balle
var gun_cooldown
var num
var dispersion
var cac

func _ready():
    init()
    $TpsRecharge.wait_time = gun_cooldown 
    pass # Replace with function body.

func init():
    pass

func _on_TpsRecharge_timeout():
    can_shoot=true

Conclusion / question:
Why the same code, with the same parameter, only work when a signal transmit the information between two scenes?

in Engine by (16 points)

Not sure if it is the cause, but you have different parents depending on how you generate it. In one case the bullet is child of the main scene and in the other it is child of the weapon that just shot it. And depending on how you are setting the start position, your bullet is starting somewhere else from where you expect it to be.

I do have different parent, it's the purpose of the two type of code. On one hand, i want cc "bullet" to be dependant of the caracter. On the other, i want my long rang bullet (normal one) to be independant. I don't think the cc bullet will be a child of the weapon, but rather of the character. Anyway, i will check other possible location of the cc bullet, thank for the advice.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.