Newbie Question: Trying to understand the camera

All I am trying to do right now is load a model, get the camera and set the camera position and direction. So I started with this (which doesn’t work):

import direct.directbase.DirectStart
import sys
from pandac.PandaModules import *

#Load the first environment model
environ = loader.loadModel("mymodel.egg")

base.accept( "escape" , sys.exit)
camera.setHpr(30.0, 30.0, -30.0) 


A roundabout way to do it would be to orient my model to the camera with…

environ.setHpr(30.0, 30.0, -30.0) 

… but I really want to just control the camera. How would I do that?

Thanks in advance for your help!

You control the object, in the same way as any other object. ^^

Isn’t environ technically “any other object”?

If so, why wouldn’t camera.setHpr(30.0, 30.0, -30.0) work if environ.setHpr(30.0, 30.0, -30.0) works? What am I not understanding here?

Yes, but it has to be “”, not just camera.

That’s why I have this line in there:


Even if I switch it to be…,0,0), 30.0, -30.0)

…it still doesn’t work. :confused:

Oh… what the…

It’s … not I read in some other example that it was but I suppose it must have changed to since then. Ok! Now this is making more sense to me!

No, it’s not It’s

But before you can set the position of, you have to disable the built-in trackball task with:


If you don’t do this, then the trackball will just snap the camera right back where it was every frame, no matter where you move it, making it appear that you didn’t move it at all.

You shouldn’t move around. That might seem to work at first, but since that movement is actually relative to, it will just get you in trouble later.


Alright… but I did already try that…

I did do base.disableMouse() and still couldn’t get my camera to point at an angle with, 30.0, -30.0).

What’s the difference between and is an internal reference object, and is the one that you actually do things to. Technically it should work with either, but wierd things could happen if you mess with

As for the fact that it didn’t work, I’m kinda nooby too, so no idea.

Thanks for the feedback. Hm, looks like I’m not the only one that ran into this: … ght=camera

AHA! I see.
I did do base.disableMouse(), but I suppose by using base.useDrive() I re-enabled it (which would make sense with what drwr is saying).

Once I took that line out it worked. Cool. :slight_smile: Thanks for the help!

Though you called base.disableMouse(), which turns off the camera tracking, you also called base.useDrive(), which turns on the camera tracking again. If you want to set an initial position of the camera and still use the drive interface, you need to load that onto the drive interface object, not onto the camera, like:

That will tell the drive interface where it should put the initial position, and you can drive around from there with the keyboard and mouse. Each frame, the drive interface will copy that position onto the camera. But if you just set the camera directly, the drive interface doesn’t know you’ve done that, and it copies its original position back onto the camera. is an ordinary NodePath, is a child of that NodePath that contains the actual Camera object. The reason there are two different NodePaths is in case you want to have multiple Cameras joined together as a single camera rig: all of the Cameras will be parented to, and when you move, it will move all of your Cameras together.

Because of the parent/child relationship, it appears to work if you move around The drive interface isn’t changing the position of every frame, so whatever transform you put there sticks; but also inherits the position of (since that’s the parent), so you can still move your point-of-view around with the drive interface. Unfortunately, you’ll get into trouble if you want to do anything more advanced with this configuration, like enable collisions or something, because the origin of your “position” as the drive interface thinks of it is no longer your actual viewpoint.

The intended design is that you always manipulate the position of You normally shouldn’t do anything at all with, except in very special cases when you actually want to do something with the Camera itself (for instance, replace the lens properties or something).

That’s making a lot more sense to me now, thanks! Such a helpful and responsive community. :slight_smile: