# 3d space game movement problem [SOLVED!]

I am making a simple 3d space game.

With this ship you fire your engines and this gives you a thrust in the direction you are facing. Then you drift in that direction as per a body in motion tends to stay in motion. Then if you rotate 90 and thrust you must add a new vector from this thrust to your old vector of drift.

How do you get your old vector and the new one to add them together? Sounds essay but I am have lots of trouble getting it to work.

Just turning with Hpr and thrusting does not work because you loose the old drift vector.

BTW, I am just moving the camera.

Thanks

Douglas

since you calculate the new vector for your movement its not difficult.
lets say you start with zero motion. if you power your spacecraft you calculate a new movement vector which is added to the old one (zero). just save the result in a variable … lets call it oldMovVec. and next frame you can do exactly the same again.

in pseudocode whit would look like:

oldMovVec = Vec3(0,0,0)
oldMovVec = oldMovVec + calculateThrustVectors()
ship.setPos(ship , oldMovVec )

for rotation… well it should look simmilar i guess. hope this helps. if not… well. was worth the try

oldMovVec = Vec3(0,0,0)
oldMovVec = oldMovVec + calculateThrustVectors()
ship.setPos(ship , oldMovVec )

The problem is taking the current camera.getHpr and getting a thrustVector from it.

Thanks
Douglas

how is your camera involved in the thing?.. i mean… arent you steering your spaceshipt (not the camera)
in case you really need the camera you should check the node.getTransform() , .getMat() or maybe getRelativeVector()
maybe one of them suits your needs

is your spaceship in first person view or how exactly are you steering it?

First I have to say I am new to both Python and Panda3d. So here is my code for the movement bits. Also I will read those commands in the morning(German time). They look good.

#def init bit.
self.accept(‘5’, self.thrustOn)#Thust
#self.accept(‘5-up’, self.thrustOff) #Thrust off

``````self.accept('8', self.facingHpr, [Vec3(0.0, 0.1, 0.0)])# Pitch up
self.accept('8-up', self.facingHpr, [Vec3(0.0, -0.1, 0.0)])
self.accept('2', self.facingHpr, [Vec3(0.0, -0.1, 0.0)]) # Pitch Down
self.accept('2-up', self.facingHpr, [Vec3(0.0, 0.1, 0.0)])

self.accept('4', self.facingHpr, [Vec3(0.1, 0.0, 0.0)])# Yaw Right
self.accept('4-up', self.facingHpr, [Vec3(-0.1, 0.0, 0.0)])
self.accept('6', self.facingHpr, [Vec3(-0.1, 0.0, 0.0)]) # Yaw Left
self.accept('6-up', self.facingHpr, [Vec3(0.1, 0.0, 0.0)])

self.accept('3', self.facingHpr, [Vec3(0.0, 0.0, 0.1)])# Roll Right
self.accept('3-up', self.facingHpr, [Vec3(0.0, 0.0, -0.1)])
self.accept('1', self.facingHpr, [Vec3(0.0, 0.0, -0.1)]) # Roll Left
self.accept('1-up', self.facingHpr, [Vec3(0.0, 0.0, 0.1)])

self.accept('7', self.facingHprFront) # face dicection of travel
self.accept('9', self.facingHprRear) # face backwards
self.accept('0', self.facingHprStill) # stop rotation and such
``````

def thrustOn(self):
self.playerAccel = Vec3(.0,.1,.0)
def thrustOff(self):
self.playerAccel = Vec3(0, 0, 0)

def facingHpr(self, val):
self.playerHpr += val

``````elapsed = task.time - self.prevtime

self.playerDelta+=self.playerAccel
self.playerDeltaHpr+=self.playerHpr #accel Hpr
camera.setPos(camera.getPos() + self.playerAccel)
camera.setHpr(camera, self.playerDeltaHpr)
#print self.playerDeltaHpr

# Store the task time and continue.

dunno if it works, but… always worth a try… your rotation should be fine as it is as far as i can see it.

btw… steering like this is pretty hard… guess in real life you would be lost in space without stabelizing functions

Well I have thought a lot about this problem and still do not have a working program.

So what I know know is this.
get key for thrust and set vec3
on up set vec3 to 0

The vec3 that must be added to the current vec3 is just moving the ship in the direction that it is facing plus the old vec3.

How do you get a vec3 that is done with camera.setPos(camera,Vec3(0,1,0))?
In any case this must be added to the old vector and then the camera must be moved to this place. IE oldvector plus new vector. Then this old+new must become the new old vector. IE old=old+new.
Hope someone out there understands this because I really wish to make this work.
Thanks all.
Douglas

``````self.playerDeltaHpr+=self.playerHpr # rotation is always relative to direction pointing