Moving Spaceship with arrow keys

Get this to move forward, backward, left, and right. I am so frustrated by this. I have spent a week looking at roaming ralph, asteroids, and other samples I can’t get this to fucking work! The model renders fine but it will not move. Please help before I blow my brains out.

from math import pi,sin, cos
import sys, os, random
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from import Actor
from direct.interval.IntervalGlobal import Sequence
from panda3d.core import Point3
from panda3d.core import Filename
from panda3d.core import PandaNode,NodePath,Camera,TextNode

speed = -5

class MyApp(ShowBase):

    def __init__(self):

        # disable camera controls for mouse
        self.keyMap = {"left":0, "right":0, "forward":0, "cam-left":0, "cam-right":0}

        # Load the environment model.
        self.environ = self.loader.loadModel("models/art/cat-skies/alice-skies--stars-egg/alice-skies--stars/stars.egg")
        # Reparent the model to render.
        # Apply scale and position transforms on the model.
        self.environ.setScale(5.25, 5.25, 5.25)
        self.environ.setPos(0, 242, 0)

        self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")

        #Space ship model
        self.player= loader.loadModel("models/art/cat-vehicles-air/alice-scifi--fighter-egg/alice-scifi--fighter/fighter.egg")

        self.floater = NodePath(PandaNode("floater"))


        # Accept the control keys for movement and rotation
    def setMovement (self):
        self.accept("escape", sys.exit)
        self.accept("arrow_left", self.setKey, ["left",1])
        self.accept("arrow_right", self.setKey, ["right",1])
        self.accept("arrow_up", self.setKey, ["forward",1])


    def setKey(self, key, value):
        self.keyMap[key] = value

    def Mover(self,task):
        startPos = self.player.getPos()
        if (self.keyMap["left"]!=0):
            self.player.setPos(startPos + Point3(-speed,0,0))
        if (self.keyMap["right"]!=0):
            self.player.setPos(startPos + Point3(speed,0,0))
        if (self.keyMap["up"]!=0):
            self.player.setPos(startPos + Point3(0,speed,0))
        if (self.keyMap["down"]!=0):
            self.player.setPos(startPos + Point3(0,-speed,0))

        #defines procedure to move the panda cam
    def spinCameraTask (self, task):
        angleDegrees = task.time * 6.0
        angleRadians = angleDegrees * (pi / 180.0) * sin(angleRadians), -20.0 * cos(angleRadians), 3), 0, 0)
        return Task.cont

app= MyApp()

I suspect that the problem is that you don’t seem to be returning “Task.cont” in your “Mover” task; as a result, that method is likely being run once and then never again. Compare it with the task just below (“spinCameraTask”).

This happened to me too quite a few times :smiley:

I wonder if it wouldn’t be better for a task to be automatically continued if the return value is None.

If anything, it should probably raise an error in that situation. That would break a lot of existing code, though.

No change after putting

    def Mover(self,task):
        startPos = self.player.getPos()
        if (self.keyMap["left"]!=0):
            self.player.setPos(startPos + Point3(0-speed,0,0))
        if (self.keyMap["right"]!=0):
            self.player.setPos(startPos + Point3(0+speed,0,0))
        if (self.keyMap["up"]!=0):
            self.player.setPos(startPos + Point3(0,0+speed,0))
        if (self.keyMap["down"]!=0):
            self.player.setPos(startPos + Point3(0,0-speed,0))

        return Task.cont()

It’s Task.cont, not Task.cont().

I know I just typed it wrong in the comment but i did fix it.
I had to add these lines:

        self.accept("arrow_left-up", self.setKey, ["left",0])
        self.accept("arrow_right-up", self.setKey, ["right",0])
        self.accept("arrow_up-up", self.setKey, ["forward",0])
        self.accept("arrow_down-up", self.setKey, ["back",0])