Question about my code

Hello guys

I am trying to implement a move system in my game, my purpose is to do a system to move the player in this case a space ship in X direction left and right, untill there everything is going right, the problem is when I try to increment the Roll angle of my ship to do a realistic movemet my spaceship should stop rotating at 45 degrees, but that’s not happening what happens is my ship continue to rotate in a infinity fashion, I have done many trials but I don’t know what is happening with my code.

Another thing I don’t know if I’m making mistakes, but when moving my ship some lags happen, I would like to have a smooth moviment and not this kind of ‘dry and hard’ movimentation. Thx.

Below is my code up now.

I cant tell where your spaces are so I cant tell you why why its looping for say, but for moving better, instead of getting its x just use

self.spaceShip.setFluidX(self.spaceShip, + elapsed*self.shipVelocity)

The Fluid will help you for collision later on and the self.spaceShip is its pos.

As for it looping my guess is that your adding the shipAngle + another time var that changes making more then the Maxangle, so instead using this… do play around with it… use something like this…

if (self.shipAngle >= self.shipMaxAngle): 
if (self.shipAngle <= self.shipMaxAngle): 

Thank you adr, the ship is moving more smoothly now, but I got problems with my setR because now the player move to where the angle is facing, for example if my player ship angle is 45 degrees the ship move in vertically and not horizontally.

Change X to Y to send it forward, if I understood you right.

there is a fundamental thing in panda3d that is setPos, setX etc. all those functions take a vector (or float) that moves a object relative to a object, usually this object is the parent object of the node you move. But you can specify the object that it’s moving relative to, by using setPos(render, Vec3(1,0,0)) you move right relative to the world coordinate, by using setPos(Vec3(1,0,0)) the object moves right relative to it’s viewing angle.
the same applies to rotation, rotate relative to the actual position, or relative to another object, which you may define.

x is right/left
y is forward/reverse
z is up/down

Thanks adr and Hypnos, I would like my ship move in the x direction no matter its angle, what is happening is my ship rotating and moving acordding its orientation for example if ship angle is 45 degrees my ship is moving into the screen, into the virtual world as I have a view from top it’s not I what I want, I want it to move left and right from top perspective, I am not sure if I don’t know if you understand, hence I put a pic showing what I am.

if you want to move relative to render (which is what you want to do), use something like:

model.setPos(render, Vec3(1,0,0))

think of it as moving relative to the world (render), x is east whatever rotation you personally have have. when you move relative to yourself, moving right depends on your rotation. (that would be model.setPos(model, Vec3(1,0,0)))

Nice thanks Hypnos. Now my ship move relative to the world, now I need found a way to make a smooth rotation, I will try something here…

Sorry, I have anotther question in my game I would like to limit the player movement only to screen boundaries, I have tried to get the x position of the player and in a if, test the current postion against a maxleftpos = 400 for example but my ship keep moving until disappear off the screen.

Make sure your not just testing for 400 or aka if playerpos >= 400, if they are, then set the player at the 399 mark playersetpos = 399 this way it looks like it “trap” from going outside the screen, note, if your move is high, you may still look like you go outside the screen for a short time (less then a ms depending how far you go for each frame).

how about:

# get the x position relative to world, add the movement in x direction, limit the x position between 0 and 400, and set it to the models position
model.setX(render, min(400, max(0, model.getX(render)+movementX)))

rotating is:

model.setH(model, rotationH)  # rotationH is a float value

but how about trying a bit more and asking less? you’ll only really learn how to code if you do it yourself (i speak from experience), every time you ask for a specific solution you may get it working, but usually you dont completely understand what you do, and even more important, you dont know how to solve a similar problem next time you encounter it…

Hypnos, at first place thank you for reply, I understand what you want to say and you are right, but before asking I do many trials, I try to solve acording to my knowledge, only after trying many times I come here in the foruns I use it as latest resource.

Other thing that I am used to is to search before asking, maybe someone have done the same question than I, but when I don’t find an answer I ask for a solution here, I believe what says in the panda home page what it’s: ‘If you get stuck, ask for help on the forums. They’re very active, and people are always willing to help’. I believe in it at most times users here think and do acording what says in this phrase.

I didnt want to offend you. I know it from myself that once i have started asking and i get further much faster then before. i love to ask again. but as i said, you do help yourself by trying out a lot, because you remember things much better.

i hope you got it working now as you intended.

(i also have to adming that after many years of using panda, i’m sometimes annoyed when reading the same questions again and again. but i gotta remember the time i started, which wasnt easy as well, sry about that)

The image of what I am doing

I am not understanding what’s happening about panda units for example if setPos is (0,10,0) the player ship is at top of screen, but if it is (0,9,0) the player ship doesn’t look like to go down just one unit, it looks like to go down several units is it relate to position relative to render and the model itself?

A session of code to rotate and move UFOs models

def loadEnemy(self):
        #Load and set enemy model
        self.enemies = []
        self.disco_node = render.attachNewNode('discoNode')
        for i in range(0,6):
            #x = random.randrange(-3,3)
            #y = random.randrange(10,11)
            self.enemy = loader.loadModel('Data/Eggs/disco')
            self.enemy.setPos(render,Vec3(i,11,10)) #0,11
    def moveEnemies(self):
        for i in range(0,6):
            self.enemy_forward = LerpPosInterval(self.enemies[i],10.0,Point3(-1,-10,10),
                                                  startPos = Point3(0,10,10), blendType = 'easeInOut')
            self.enemy_backward = LerpPosInterval(self.enemies[i],10.0,Point3(1,10,10),
                                                  startPos = Point3(0,10,10) , blendType = 'easeInOut')
            self.enemy_rotation = LerpHprInterval(self.enemies[i],5.0,Point3(360,360,360),
                                                  blendType = 'easeInOut')