base.cam and base.camera -> problems with reparenting

Hi all,

i’ve got a bit of an issue that I can’t quite get a handle on. I’m trying to reparent the camera to my player object, without loosing the default mouse behaviour for now and ofcourse with an offset (so that its not inside the model).

For this i’ve tried the following code snippet:

from direct.showbase.DirectObject       import DirectObject      
class Player():
    def __init__(self):
        self.model = loader.loadModel("models/ship/ship")
        self.model.setScale(0.01)
        self.model.reparentTo(render)
        self.model.setPos(0,0,0)
        print "Setting base.camera.pos"
        base.cam.setPos(0,-20,10)
        base.cam.lookAt(self.model)
        base.cam.reparentTo(self.model)

Result: Camera has a nice offset - Default mouse behaviour is not available.

If however I replace base.cam.* with base.camera.* (this was actually my first try as thats the recommendation) - the mouse behaviour still works, but the camera doesn’t get an offset.

When I remove the reparentTo, everything works as expected - but I’d need to keep the pos relative to self.model myself, instead of the engine doing that for me.

(Note: this is a seperate class file, called by main.py - will not function as standalone code :wink:)

Anybody know how I can make it that it has both the default mouse functionality and the offset?

Thanks for any insite any of you can give.

I believe the problem you’re having is reparentTo is making the camera inherit the position of self.model when you call it. You could try reparenting it first and then calling setPos() to make it work in the new reference frame.

Maybe it did but it was too small to notice. Nodes inherit scale from their parent, and you have set the parent’s scale to 0.01. Try setPos(0,-2000,1000) and see if that is where you wanted it.

Something else to try is reset the trackball with the following lines:

base.trackball.setOrigin(self.model.getPos())
base.trackball.setRelTo(self.model)