Problem with lazer

Hi everyone,

I’m having a architecture problem… Any help will be appreciated. It’s a space shooter game, when the player press on “fire”, a lazer objet is created. My problem is that the name in my class is static, so when the player press “fire” a couple of time, the node are re-created and the previous one stop moving.

Here is the code for the lazer class:

class WeaponDarkLazer:
    def __init__(self, world, basePos, baseH): = world
        self.pos = basePos
        self.baseH = baseH
        self.hitDammage = 1
        self.speed = 30
        self.autodestruction = 3
        self.totalElapsed = 0
    def loadModels(self):
        self.orbit_root_lazer =
        self.orbit_root_lazer.setPos(0, 0, 0)
        #Load the beams
        self.leftBeam = loader.loadModel("models/darklazer/cylinder.egg")
        self.leftBeam.setColor(0, 1, 0, 1)
        self.leftBeam.setHpr(0, 90, 0)
        self.leftBeam.setScale(0.04, 0.04, 0.5)
        self.leftBeam.setX(self.leftBeam.getX() - 0.5)
        self.rightBeam = loader.loadModel("models/darklazer/cylinder.egg")
        self.rightBeam.setColor(0, 1, 0, 1)
        self.rightBeam.setHpr(0, 90, 0)
        self.rightBeam.setScale(0.04, 0.04, 0.5)
        self.rightBeam.setX(self.rightBeam.getX() + 0.5)
    def move(self, elapsed):
        self.totalElapsed += elapsed
        if (self.totalElapsed < self.autodestruction):
            self.orbit_root_lazer.setH(self.orbit_root_lazer.getH() + (elapsed * self.speed))

I don’t know if there is a way to create a dynamic name with an id? So there will still be my orbit_root_lazer but each lazer will have it’s own node like lazer1node, lazer2node that will increment each time the player press “fire”.

So is it possible? Or do you have any other idea to create the same effet?



There is :


Thanks for you answer but it’s not exactly what I meant.

What I want is something like this.

def loadModels(self, id): 
     self.orbit_root_lazer"id" =

Where “id” would be the value of the id… I want that each time loadModels is called there is a new node that is created with a new name because if I don’t do that, each time there is a new lazer that is created, you don’t overwrite the existing one…

Maybe this is stupid… any idea to help me?


I think I get it…

I didn’t see the problem in the good way. Now it works… I can’t post my code here because it needed change in other class and everything.