How to get bullets to spawn on gun and go towards mouse position?

Godot Version



Hello all, I am currently trying to setup a system that will have multiple guns, that the player can equip and each have different fire rates, damage, etc. What I thought I could do was create an Area2D gun, and an Area2D bullet that would have specific values for that weapon. Example, Starting_Gun would spawn and shoot Starting_Bullets, I was thinking this setup would be easiest to use as a template for future guns. However, I am unsure, after spending hours online looking at code and various tutorials and attempting to combine them for my setup, how to implement this set up. I need help with the coding part of the Starting_Gun(Area2D) and Starting_Bullet(Area2D) how would I go about coding those two things?

i made an topdown shooter a while ago, and the way i did was to have and Node2D with the marker setting the starting position of the shoot, and the Area2D as the ammunition, in the code for the Area2D i only have the position.x += (set speed) let’s use 1000, on the Node2D code i create an instance of the Area2D, and added to the tree everytime i call the func Fire() using the Marker as starting point and i rotate the Node2D using the look_at() function to look for the global Mouse position.

i know that i have to be more clean on my explanation.

Anywhere you could ink me the code for those two things you created so that I could take a look at it?

I cannot link more than one print, but i can send you an tutorial that you can find useful is old dated, but can help.

When I follow that video I get this error:

Invalid call. Nonexistent function ‘instance’ in base ‘PackedScene’.

If you are only able to link one print, can you link your gun one

Can you show me the code? i can help with that


I’ve actually got it working now, using the resources you provided me with, thanks luishkruger!