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.
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 …
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 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
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.
You could hide it, or position it way off screen in a spot the player will never get to. But I suspect this doesn’t answer your question. I suspect you mean the unused weapons. What I don’t understand is why you don’t want to delete and recreate the weapons. Because you have separate sprites for each weapon, your condition of not deleting or creating makes things a lot trickier. It’s much easier if you have one weapon sprite in the scene that the player uses, and if it’s part of the object group then you just need to refer to the object group name no matter which weapon is in use.
If you’re using the array method from my earlier post, then you could make it the first element in the array.
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 ....
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
Hi, it’s me again, I got it working but I had a problem. It deletes the objects and creates new ones. The thing is that I work with weapons and weapons have bullets, so when I delete and create a new weapon, the ammo fills up. What I want and I was trying for a long time to do is for the objects to move instead of being deleted and created but I got stuck. do you think you can help me?