# some movement problems

this is my code that moves my ship:

``````      def move(self, dire):
if dire == "up":
self.newp = self.battleship.getP() + (9 *globalClock.getDt())

if dire == "down":
self.newp = self.battleship.getP() - (9 *globalClock.getDt())

if dire == "left":
self.newh = self.battleship.getH() + (9 *globalClock.getDt())

if dire == "right":
self.newh = self.battleship.getH() - (9 *globalClock.getDt())

self.procent = self.proc/100
battleshipPrevPos = self.battleship.getNetTransform().getMat().getRow3(1)
battleshipPrevPos.normalize()
self.battleship.setPos(self.battleship.getPos() + self.procent*(battleshipPrevPos*(globalClock.getDt()*10)))
self.battleship.setHpr(self.newh,self.newp,self.newr)

self.accept("q", sys.exit)
self.accept("escape", sys.exit)
self.accept("w-repeat", move, [self,"up"])
self.accept("a-repeat", move, [self,"left"])
self.accept("s-repeat", move, [self,"down"])
self.accept("d-repeat", move, [self,"right"])
self.accept("+-repeat", move, [self,"faster"])
self.accept("--repeat", move, [self,"slower"])``````

idea is that there is a standard speed (10) and there is the speed controler(self.proc) if you press + it self.proc will be increased and the ship will go faster because there is a higher value.

the only problem is that it gives an error:
unsuported operand type(s) for *: int and libpanda.Vbase3

how do i correct this?

assainator

You can’t multiply an int with a vector:

``123 * Vec3(1,2,3)``

But you can do this:

``Vec3(1,2,3) * 123``

i corrected my code, but if i repeatively press +, the self.proc and self.procent remain the same.

so in the beginning, i state that self.proc = 20
this should move the ship, it doesn’t.

any idea’s why this is?

Aha.

``self.proc/100 ``

If you do 20/100, the result is 0, since if you’re dividing an integer by an integer in Python, you get an integer as result.
So, make one of the values a float:

``self.proc/100.0 ``

thanks i have it working now.

tough i have a question:

in homeworld 2 they have a very nice background. (in case you don’t know homeworld 2: youtube.com/watch?v=Nyt06cv1VvE)

just create a sphere and turn it inside out and add a texture?
or is there a very efficient way in panda to do this?

assainator

That’s the idea - you usually create an inside-out skybox or skysphere, as it is called, and apply a nice texture to it. I bet they do it the same way in Homeworld.

The usual way to implement this in Panda is to reparent the sphere/box around the camera, set it in a background bin (so it will be always in the background), disable depth write/test and add a CompassEffect.
I’m sure there are examples at the forums how to do that.