Third Person

I know… there is already a thread about this…
But I don’t understand the code, so i ask :slight_smile:

How can i get the Pitch/Yaw/Roll of an actor?

I want to know this, because i want to know, where i have to place the camera…

And how can i calculate the position of the camera?

I want the camera behind the actor… but the actor moves xD

Please help!


You could do either actor.getHpr() which will return a Vec3(yaw, pitch, roll) or get them one by one using actor.getH(), actor.getP() and actor.getR().
Because the Y was already used for the Y-position, the Panda3D developers had to call it Heading instead of Yaw, thus the H.

A position can be retrieved by doing object.getPos(). If you want an absolute position you could use object.getPos(render).

All of this is also explained in the manual:

If you want the camera behind your actor, don’t set its position every frame-- instead, reparent the camera to the actor and give it an offset in the -Y direction.

In Panda pitch yaw roll is heading, pitch and roll. To get them use NodePath.getHPR(), or you can get them individually with getH(), getP() or getR().

If you want to stick the camera on the actor, you could reparent it to the actor ( ) but thats a slightly bad idea as the camera would also inherit the HPR transformations of the actor. Another idea is to have a task getPos() the actor and then doing a setPos() on the camera with an offset.

thanks for your help :slight_smile:

Hmm… i already tryed to reparend the camere to the actor… but how can i set the offset?

Thanks for your help anyways :slight_smile:

Hoping for more help,

After you’ve reparented the camera, set the offset by simply using setPos (or setX/Y/Z), which will set the position relative to the parent node (in this case the actor.) Then, you will want the camera to look at the actor.

In short:


You might want to set a different offset, or use a positive value (like 5) if your model faces the Y- axis (like ralph).

Thank you very much :slight_smile:

Well… next Problems: you can stil use your mouse and your sight is veeeery small Oo

Please help :slight_smile:


btw: The offset won’t work :’(

If you want to move or reparent the camera around, you must first disable the mouse controls. So, before doing anything to the camera, call this:


If the offset will still not work then, you might need to tweak the -5 value, try 5 or a smaller or higher value.

Thanks again :slight_smile:

Hmm… the lookat command seems not to be working…

Heres an example screenshot with a panda:

This was made with an offset of -550

If i set no offset, it will be the same…

Here’s the code:

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.gui.OnscreenText import OnscreenText 
from direct.task import Task
from import Actor
from direct.interval.IntervalGlobal import *
import math
import cPickle, sys


base.accept ("escape", sys.exit)

environ = loader.loadModel ("models/environment")

Panda = Actor.Actor("models/panda-model",{"walk":"models/panda-walk4"})

camera.reparentTo (Panda)
camera.setY (-550)
camera.setZ (20)
camera.lookAt (Panda)

#Create the four lerp intervals needed to walk back and forth
pandaPosInterval1= Panda.posInterval(13,Point3(0,-10,0), startPos=Point3(0,10,0))
pandaPosInterval2= Panda.posInterval(13,Point3(0,10,0), startPos=Point3(0,-10,0))
pandaHprInterval1= Panda.hprInterval(3,Point3(180,0,0), startHpr=Point3(0,0,0))
pandaHprInterval2= Panda.hprInterval(3,Point3(0,0,0), startHpr=Point3(180,0,0))

#Create and play the sequence that coordinates the intervals
pandaPace = Sequence(pandaPosInterval1, pandaHprInterval1,
  pandaPosInterval2, pandaHprInterval2, name = "pandaPace")

Controlling the camera is covered in the manual so I suggest giving it a good read through. To control the default camera, use So, etc.

well… now I can see textures, but the offset won’t work…

stop telling me “rtfm” i hate it…

Well as far as I can see nobody here did that, they just pointed you to the manual page (common state changes) which adresses kinda all the issues you mentioned. It might be a good exercise to just read the manual over and over and try some things to get your problem solved, this way you’ll get a much better understanding of panda3d than you’ll ever get by having other people solve your problems.

about the lookat fucntion not working: if you want your camera to look at the panda all the way trough the animation, you’ll have to call the lookat method every frame. Check out the task handling manual here: to learn how you can have panda call “lookat” every frame.

good luck with the game.

You could also take a look at the Roaming Ralph example in the samples dir of your panda distribution. It clearly shows the setup of a third-person camera.