hello everyone, I would like to resume an old post opened by me long ago.
I’m still looking for a solution on player weapon switching.
this is my current code where i can add two weapons and remove it one at a time:
(I believe that pick weapons based on the player’s z-order is wrong)
my problem now is to understand how to hide the first weapon when the player takes the second and above all how to switch the weapons linked to the player
I have not found any tutorial on this and I have left this out to dedicate myself to doing something else but this time I want to succeed.
please help me i’m going crazy
I didn’t understand what you want exactly >> but if you want to change the weapons only delete the last weapon and variable after your condition … then use an action ( create object ) for a new weapon in the same last weapon place (X , Y) with a new variable …
i need the player to be able to carry up to 2 weapons (like nuclear throne)
well… change weapon position when you create or change a new weapon object and make it stay visible when a player doesn’t use it … by point in your player body or anywhere you want
What I do is add all the weapons to the player and use link weapon to player then hide all and make visible only the equipped weapon, with Take into account all Weapons attached to Player
I can’t understand it, how can I then do to be able to interchange the linked weapons?
why do you use linked objects? only make weapon position in point inside your player … it will set weapon always with your player
I use linked because some of the weapons can be thrown like the boomerang or vaccum type grenades so they have to detach from the player position x time and then return to the player position
the weapons are not like bullets or bombs. you can set point in said weapon for making a bullet or bomb … then I think above user wants visibility weapons not hidden
Here’s a link to an example project that does just this.
And here are the screen shots in case the files get removed at any time.
Setup (player has top down movement behaviour) :
sorry it’s still me … I still have a question to ask.
in my old code the player when he collided with the weapons this variable was activated that was used to change the position of the weapons and to make them rotate.
my question is :
how do I change the position of the weapon without having to delete it when taken and recreate it when it was left.
when the player has collected two weapons how do I select which of the two should shoot
in my game the player has no hand weapon animation, the weapons are separate sprites with their own animation.
I ask for forgiveness but I cannot understand
now the collected weapon is deleted from the ground and recreated on the player but when the x key is pressed to collect the next weapon it always recreates the same weapon taken previously.
plus I can’t figure out how to switch guns in hand
Yes, because the weapon held on the player will be the one nearest the centre of the playerhitbox (I’m assuming you’re placing the player’s weapon at the centre of the player/playerhitbox sprite). Try inverting the condition
Pick the weapon nearest to ....
Do you reset the instance variable grabbed of the weapons to 0 when you drop them? If so, you could add the condition that weapons.grabbed = 0.
i had already tried using the variable grabbed = 0 to drop the weapons but this doesn’t work.
the weapons remain the same attached to the player and creates several problems with the hud inventory.
I do not know what to do