Control the Actor how?

So i have a actor running not panda
but i need to figure out
how can i control the actors movements using the keyboard?
Keys example
Arrow up
Arrow down
Arrow Right
Arrow left
then how can i make the camera follow the actor?

^.^ I’ve kinda of ask this too. Its in the code here, just have to get what you need out of it. Note do look at the lower end of the post to get the right code.

Help the code isnt working
i get constant errors!
when i entered that code in

import direct.directbase.DirectStart
from direct.task import Task
from import Actor
import math
from pandac.PandaModules import CollisionHandlerQueue,CollisionRay
from pandac.PandaModules import Filename
from pandac.PandaModules import PandaNode,NodePath,Camera,TextNode
from pandac.PandaModules import Vec3,Vec4,BitMask32
from direct.gui.OnscreenText import OnscreenText
from import Actor
from direct.task.Task import Task
from direct.showbase.DirectObject import DirectObject
import random, sys, os, math


Figure out what directory this program is in.


Function to put instructions on the screen.

def addInstructions(pos, msg):
return OnscreenText(text=msg, style=1, fg=(1,1,1,1),
pos=(-1.3, pos), align=TextNode.ALeft, scale = .05)

Function to put title on the screen.

def addTitle(text):
return OnscreenText(text=IceBlade, style=1, fg=(1,1,1,1),
pos=(1.3,-0.95), align=TextNode.ARight, scale = .07)

class World(DirectObject):

def __init__(self): 
    self.keyMap = {"left":0, "right":0, "forward":0, "cam-left":0, "cam-right":0},0,0,1)) 

    # Post the instructions 
    self.title = addTitle("Panda3D Tutorial: Roaming Ralph (Walking on Uneven Terrain)") 
    self.inst1 = addInstructions(0.95, "[ESC]: Quit") 
    self.inst2 = addInstructions(0.90, "[Left Arrow]: Rotate Ralph Left") 
    self.inst3 = addInstructions(0.85, "[Right Arrow]: Rotate Ralph Right") 
    self.inst4 = addInstructions(0.80, "[Up Arrow]: Run Ralph Forward") 
    self.inst6 = addInstructions(0.70, "[A]: Rotate Camera Left") 
    self.inst7 = addInstructions(0.65, "[S]: Rotate Camera Right") 
    #Load the first environment model 

environ = loader.loadModel(“models/Castle/Deaths Castle.x”)
#Run the tutorial

Create the main character, Ralph

    # ralphStartPos = self.environ.find("0,0,0").getPos() 

self.ralph = Actor(“models/human/ralph.egg”,{“run”:“models/human/ralph-run.egg”

Accept the control keys for movement and rotation

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])
self.accept(“a”, self.setKey, [“cam-left”,1])
self.accept(“s”, self.setKey, [“cam-right”,1])
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(“a-up”, self.setKey, [“cam-left”,0])
self.accept(“s-up”, self.setKey, [“cam-right”,0])


Game state variables

self.prevtime = 0
self.isMoving = False

    # Set up the camera 


#Records the state of the arrow keys 

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

Accepts arrow keys to move either the player or the menu cursor,

Also deals with grid checking and collision detection

def move(self, task):elapsed = task.time - self.prevtime

If the camera-left key is pressed, move camera left.

If the camera-right key is pressed, move camera right.
camright =
if (self.keyMap[“cam-left”]!=0) - camright*(elapsed20))
if (self.keyMap[“cam-right”]!=0) + camright

save ralph’s initial position so that we can restore it,

in case he falls off the map or runs into something.

startpos = self.ralph.getPos()

If a move-key is pressed, move ralph in the specified direction.

if (self.keyMap[“left”]!=0):self.ralph.setH(self.ralph.getH() + elapsed300)
if (self.keyMap[“right”]!=0):self.ralph.setH(self.ralph.getH() - elapsed
if (self.keyMap[“forward”]!=0):backward = self.ralph.getNetTransform().getMat().getRow3(1)
self.ralph.setPos(self.ralph.getPos() - backward*(elapsed*5))

If ralph is moving, loop the run animation.

If he is standing still, stop the animation.

if (self.keyMap[“forward”]!=0) or (self.keyMap[“left”]!=0) or (self.keyMap[“right”]!=0

If the camera is too far from ralph, move it closer.

If the camera is too close to ralph, move it farther.

camdist = camvec.length()
if (camdist > 10.0) + camvec*(camdist-10))
camdist = 10.0
if (camdist < 5.0) - camvec*(5-camdist))
camdist = 5.0

The camera should look in ralph’s direction,

but it should also try to stay horizontal, so look at

a floater which hovers above ralph’s head.

self.floater.setZ(self.ralph.getZ() + 2.0)

Can you put code tags? I think spacing your problem, the’re not set up right.

you forget to restore the time

self.prevtime = task.time
return task cont

or just paste all ralp tutorial in your code that must be working

Im getting errors
i need a simple code
that will let me control the model through arrow keys

Will some one give me the code?
i readed tourtoial and it gave me errors when i tried it

The Roaming Ralph example is really the place where you can find the code you want. If it gives you errors, it could mean that there is something wrong with your panda3d installation or with the way you start the program.

Perhaps you could describe how you start the example program and what errors you get?