How do make it so i can equip multiple guns and also that bullet spawns at the tip of the gun

so i started working on a top down shooter and i’ve barely done anything. but i am currently stuck on two things and i have looked and i haven’t found anything to solve these problems. first i can’t get the bullet to spawn at the right spot. it’s either at the center of the player model or it just looks good in one direction but bad in every other angle.( i recorded a short video but i guess i can post it here for some reason.) anyways here is what the points are.

player

bullet

pistol

and my other problem i’m struggling with is how would i make it so the character can equip more guns i.e press 2 and swtich to sub machine gun and pres 3 for shotgun, etc. again i looked on these forums and watch a fair amount of youtube videos but i just can’t find a good answer. hopefully someone can help here’s everything i put in so far

Gdevelop is case sensitive

Learn to adapt some rules into your naming
ForExampleIWentWitCapitalizingEachFirstCharacterOfWordInMyNames

So i would not even need to remember how i wrote it because by that rule i would know it was GunPoint

On other hand why not just go with GP?

As for different weapons i would just go with animations

Also idk where did you get to string cursor x

You should fire bullet from player at player.PointX(“gunPoint”) same for Y toward player.Angle()

BUT action to rotate player toward CursorX() and Y should by above fire action
Otherwise rotation will happen AFTER you fire bullet

Now i look into your events and only in object points you typed gunPoint
Everywhere else in your events NOTHING is capital everything is in lower case
Maybe you should stick to that instead of my way of capitalizing each 1st character

I mean adapt some rules for yourself
You are closer to going with all lower case so i would stick to that

okay i did what you said and it looks like the bullet is basically where i want it to be. but i’m still having an problem with switching the animations. right now i can’t figure out how to change the sprite animation and have it stay the same. i found a tutorial that does that but when i put in the code it doesn’t do that. i still have the same problem of the spirite changing when i press 1 but it changes back to the default sprite when i let go. i want it to like press 1 changes to another gun and stay that way until you press 2 or 3.

1st of all remove that variable cause it is useless there

2nd your weapon should be separate object you attach to player
So now no matter to what animation you change player your weapon will work independent

And you would simply change animation of weapon to number you pressed

So for example you could change animation of weapon to 1 when 1 key is pressed
And 2 when 2 is pressed and so go on

okay so good news you were right. i was able to get the submachine gun and shotgun sprites to work. bad news…how do i make it so they fire correctly. right now the shotgun blast comes out when i have the pistol equipped and the also the pistol is firing automatically instead of being semi automatic like how it was before. so how would i make so each fires the way there are supposed to. i made a sub machine gun bullet object but i don’t think i will have to use that but i guess let me know if i do. but this is what i put in and thought would work but didn’t

Use a weapon system that supports multiple guns and set the bullet spawn point to the gun’s muzzle position for accurate firing.

1 Like

It’d be more helpful if you could either come up with such a system, a suggestion on how to build such a system or include a link to an existing system.


In the events that check left mouse button (third and fifth events), add 2 conditions:

  • the first condition to add is one to check the animation of pistol. So in the 3rd event check it’s “hangun” (that’s how you misspelt it, btw), and in the last event check it’s “shot gun”
  • the second condition to add is a “Trigger once while true” to both the events. Otherwise it’ll keep trying fire every game frame.
  • also, in the last event change the “left mouse button released” condition to a “left mouse button is down”.

Double click your weapon object and go to points
Then turn off that option that says share points between animations

And now on each animation change your gunpoint to where you want bullets to come from

Use a weapon manager to switch between equipped guns and set each gun’s muzzle as the bullet spawn point using a child transform.

It’d be more helpful if you could either come up with such a system, a suggestion on how to build such a system or include a link to an existing system.


This ain’t Unity…

sorry but i can’t find a check animation prompt. i found the trigger option but it just says there’s nothing to configure. also on the last event if it’s changed to left mouse button is down then that just makes the shotgun be automatic which i don’t want.

so i didn’t add any trigger events and not sure if i did exactly what you said. but maybe i did. anyways i got every gun firing the way i want them to now. i guess this post is now solved. i guess i’ll post a screen cap in case someone in the future has this problem. again i don’t know if this is what you told me to do…but it’s working so i guess we’re good :man_shrugging: