#How to make a weapon switching system?

1 messages · Page 1 of 1 (latest)

gusty wolf
#

I am trying to make a weapon system in Godot2d that is explained in the picture. Does anyone have any ideas or suggestions of how to make this? Thanks! (if anyone has any questions about the drawing you can ask too) (also I am not a good drawer sry)

fierce sequoia
#

You could use an enum, dictionary, and var cur_weapon to make this. (At least, that's what I would do.)

enum WeaponSlots {FIRE_SWORD, ICE_SWORD, ELECTRIC_SWORD} var slots_unlocked = { WeaponSlots.FIRE_SWORD: true, WeaponSlots.ICE_SWORD: false, WeaponSlots.ELECTRIC_SWORD: false, } var cur_weapon = WeaponSlots.FIRE_SWORD

You can get the next/previous weapon using clamp()

`func switch_to_next_weapon():
cur_slot = clamp(cur_slot + 1, 0, slots_unlocked.size())
if !slots_unlocked[cur_slot]:
switch_to_next_weapon()
else:
switch_to_weapon_slot(cur_slot)

func switch_to_last_weapon():
cur_slot = clamp(cur_slot - 1, 0, slots_unlocked.size())
if !slots_unlocked[cur_slot]:
switch_to_last_weapon()
else:
switch_to_weapon_slot(cur_slot)`

You can put the logic to show a different weapon graphic or whatever you want to do in switch_to_weapon_slot(_new_slot) etc

On attack and special attack inputs you can check cur_slot == WeaponSlots.FIRE_SWORD or the other weapons and handle the logic as needed

#

You can use an Area to detect the player being near the table and popping up the UI. Only allow the player's weapon switching to run when they're near the table

#

something like that.