basic gunnery

so I’m trying to make my gunnery model work, I think I’ve almost got it but there is one thing that is making me scratch my head.

here’s what I have so far:

in my task loop:

if (self.keyMap["fire"]!=0):
           for weapons in range(len(self.loadout)):
                if self.arming[weapons] != 0 and self.ammo[weapons] != 0:
                    while self.firect[weapons] <= 0:
                        self.firect[weapons] = self.firect[weapons] + float(self.loadout[weapons]['ROF'])
                    self.firect[weapons] = self.firect[weapons] - elapsed

basically, click and it will look at all of the weapons you have, make sure they have ammo and are armed, if so they look up the weapons rate of fire and do some stuff with the clock. if enough time has passed since the last shot: self.firegunz(weapons)

this is what firegunz does so far:

def firegunz(self, weapon):
        retXa = screenCenterY * self.reticleA.getX()
        retZa = screenCenterY * self.reticleA.getZ() 
        ammo = self.ammo[weapon]
        self.ammo[weapon] = ammo - 1
        shotSpeed = int(self.loadout[weapon]['Velocity'])
        aimVec = Vec3(retXa, aspectDist, retZa) * shotSpeed
        if self.loadout[weapon]['type'] == 1:
            firevec = self.velocity + aimVec
        myShot = weapon * 10000 + ammo

        ##bulletNode = render.attachNewNode("bullet#%d" %myShot)
        ##myBullet = loader.loadModel("models/tracer")

basically I find where my reticle is, find and deduct ammo, find the vector the reticle corresponds to and multiply it by the muzzle velocity. I add the velocity vector of the ship to the firing vector.

here’s where it gets hazy. myShot is a bullet ID number basically, and I throw it into a list. at the same time I throw the bullet’s vector into a list. So I’ve got 2 parallel lists showing bullet ID and the vector it should travel on.

so… I need to create nodes and load models for the bullets and assign each its vector to be updated every frame (back in the task loop). I’m not real clear on how to attach my bullet ID number to the bulletNode. advice?

looks like you could make good usage of python’s directories
directory = {ID : nodepath}

you can, of course put them into lists like
[ {ID:nodepath1 } , {ID2:nodepath2} , … ]

Dictionary. It’s called dictionaries :slight_smile:

dump me… of course dictionaries…
directories… such a nonsense :smiley: looks like i forgot to import brain today