0 votes

i'm trying to have my sword instance rotate to my character's direction but when i try to set the sword's rotation it gives me this error here's the code:

this is in the player script:

func instance_melee(_direction):
    var melee_inst = melee.instance()
    var rot_direction = _direction.angle()
    melee_inst.set_sprite("katana", rot_direction)
    add_child(melee_inst)
    connect("set_meleeWeapon_pos", melee_inst, "set_pos")

this is in the melee_weapon script:

func set_sprite(weapon, rot):
    sprite.rotation_degrees = rot
    sprite.scale = Vector2(2,2)
    sprite.texture = load(melee_weapons_dict[weapon]["weapon_sprite"])
    sprite.hframes = melee_weapons_dict[weapon]["nb_frames"]
    animate(weapon)

PLEASE HELP I'M STUCK!!!!

in Engine by (120 points)

where is sprite set and what to?

Does it have a value?

Add a print(sprite) to your set_sprite function.

sprite is set to a sprite node that is a child of this area2d it print's out null if i print it out

So, sprite isn't set appropriately - it's null - which is the problem. So, you need to find out why the variable doesn't have the value you expect. If you need help, post the code that sets the variable, as well as what your scene tree looks like, and which node in the scene tree has the above script associated with it.

1 Answer

0 votes
Best answer

I found out the probloem i was simply calling this function before adding the instance of the melee weapon to my scene i fixed everything and it's working
THANKS to jgodfrey for helping me realise this !!!

by (120 points)
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 Frequently asked questions and 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 [email protected] with your username.