I am trying to stick a model in front of the base camera (kind of like a chase cam of the model). while I move the camera, I reset the position of the model by using camera’s position, this works fine when moving forward and backward:
self.stickMbox.setPos(base.camera.getX(), base.camera.getY()+8, base.camera.getZ() -2)
self.stickMbox.setHpr ( base.camera.getHpr() )
When I start doing turn right and left, I use this to turn the camera (without resetting the position and Hpr).
base.camera.setH(base.camera, -1 ) #right
base.camera.setH(base.camera, +1 ) #left
I then set my sticking model using:
self.stickMbox.setH ( base.camera.getH()) #right and left
This does not work, the camera turns correctly, but the model did not follow the cam. It seems that the heading of the model did not get changed. I also tried resetting the Hpr of the model, that doesn’t work either…
Can anyone shed some light on this? thanks in advance.
If you want a chase cam, you should make the camera the child of the node, not the opposite. If you do that, your player will orbit along the camera when you rotate the camera, as if he is running in circles. Imagine a line connecting the camera with the players back and imagine rotating the camera if you dont understand it.
Just do this:
and rotate and move the player. thats the simplest chase cam you can get. Also, you dont really need to set the positions and rotations of the child explicitly, chidren inherit the transforms of their parents.
You could use tasks instead of parenting if you, for example, wanted the camera to follow the player, but not rotate with it. There are other ways, like having a parent for both player and camera and moving the parent node, but rotating the player instead, since player is not parent of camera, then camera wont rotate with it.
The way you suggested works, thanks!!