Char look at cam : cam relative to char

Hey,

My base.camera is relative to my char. I can rotate the camera around my char, but now I try to let my char headsUp to my camera, after it has turned.

I tried this code, but it didnt work:

                self.char.headsUp(base.camera)
                #self.char.setH(self.char.getH() + 180)
                self.camHasChanged = False

I think , thats because my camera is relative to my char and the camera turns with the char, when the char trys to look at the cam. How can I fix that?

reparenting the camera to a node which doesnt rotate with the char. for example render. using wrtReparentTo will respect the camera’s current transforms,so it wont change it’s position.

base.camera.wrtReparentTo(render)
self.char.headsUp(base.camera)
##do whatever rotating you want to now, 
##the camera will remain at it's position
base.camera.wrtReparentTo(self.char)

Small sidenote: wrtReparentTo() is rather expensive. You shouldn’t do it every frame.

A solution would be using two nodes for your charater: one for its position and the second for its rotation. Then your camera can be parented to the position node and only inherit the rotation of the other one when triggered.

Yet another idea would be a task, that changes the rotation of camera in respect to render every frame.

Thats the easiest way in my opinion.

dummynode = render.attachNewNode('dummynode') 
dummynode.reparentTo(render)

Then you can reparent your character model and camera to this.
If you want to move the character, move the dummy node (which is a parent of both), if you want to rotate your character, rotate the character node. Since character node is not parent of camera, it won’t affect the camera.
I learned this idea from the forums.

Isn’t this supposed to do just that?
panda3d.org/manual/index.php/Compass_Effects

Sure, but a compass effect gives you very little control. Actually you can only turn it on and off. with a custom task you can bring in other factors and triggers.