everytime a new instance creates the velocity of speeds up

        def genbullets(Task):

            playmusketsound()
            b=bullet()
            b.bullet.setX(self.farmer.getX()) #Set initial position
            b.bullet.setZ(self.farmer.getZ())#zpos = zm.card_gravestone_1.getZ() #get z axis height position
            bulletArray.append(b)      
            self.farmer.find('**/+SequenceNode').node().play(0, 5)
            print 'newbullet'
            bullettimer()
               
            
        def bullettimer():
            taskMgr.doMethodLater(random.randint(1,5), genbullets, 'MyTaskName', extraArgs=[], appendTask=True)
            
        taskMgr.doMethodLater(random.randint(1,5), genbullets, 'MyTaskName', extraArgs=[], appendTask=True)
        
def updatebullet(Task):
    pos=0
    i=0
    ii=0   
    for z in bulletArray:
        for i in range(len(bulletArray)-1,-1,-1):
            if not bulletArray[i].bullet.isEmpty(): 
                pos=bulletArray[i].bullet.getX()
                posZ=bulletArray[i].bullet.getZ()
                bulletArray[i].bullet.setX(bulletArray[i].bullet.getX()-.0008)
                print bulletArray[i].bullet.getX()
                
                for x in zombieArray:
                    for ii in range(len(zombieArray)-1,-1,-1):
                        if not zombieArray[ii].basezombie.isEmpty():
                            zposZ=zombieArray[ii].basezombie.getZ()
                            if posZ-zposZ < 0.05:
                                zpos=zombieArray[ii].basezombie.getX()
                                collpos=pos - zpos
                                if collpos <= 0:
                                    bulletArray[i].bullet.removeNode()
                                    
                if bulletArray[i].bullet.getX() <= -0.75:
                    bulletArray[i].bullet.removeNode()
                
    return Task.cont
        
taskMgr.add(updatebullet, 'bullettask')    

I had this problem before but it was caused indentation error- this time though I can’t get what I am doing wrong- I even printed out the getX to see if it moved the same. And they do.

Why when a new bullet creates does it speed up all the bullets? The objects move at the same step distance and at the same number of steps-

941 steps at -.0008 per step- the last object took 1.9528689000000 seconds to cover the distance, but the previos object took 2.22112000000 seconds to complete- so that means that by the time the last instance had finished there was an over decrease in time by 0.2682511 seconds from the previous instance.

So if the steps stay the same, the rate stays the same, but the time elapsed changes does that mean I am somehow altering the framerate- speeding it up?

I am really confused

JB SKaggs

I just noticed it speeds up my whole game- so that the all objects move faster.

How could I be doing that?

Well, I don’t know why your frame rate would be speeding up, precisely, but it is true that your code is not written to be frame-rate independent, which means that as your frame rate fluctuates (which is normal), so will your animation speed fluctuate.

Instead of adding a fixed amount every frame to your bullets’ positions, you should be adding an amount proportional to the amount of time that has elapsed since the previous frame. That sounds complicated, but it’s not, because Panda provides this time: just multiply the amount you add by globalClock.getDt(). (You’ll probably need to re-scale the amounts when you do this, because globalClock.getDt() is usually a small number.)

David

I just had a quick look at it, and I am dead tired, but this seems strange:

def updatebullet(Task): 
    for z in bulletArray: 
        for i in range(len(bulletArray)-1,-1,-1):
            bulletArray[i].bullet.setX(...)

Assume bulletArray has length n. The outer loop is executed once for each item in bulletArray. Then, for each execution of the outer loop there is an inner loop, which is executed n times (since n is length(bulletArray)). The inner loop moves the bullets, so each of the n bullet is moved n times!!! Moving n times is effectively n times the intended speed.

The more bullets you get the more often your bullets will be move per frame.

So, rewrite you code with only one loop. And while doing so, try to make it frame rate independent (move the bullet by dx = ellapsedTime * speed).

In hind site double looping seems dumb- but it made sense when I wrote it at midnite. The human mind is strange in that way.

JB