Editing Roaming Ralph to learn

Hi guys, I’m starting a small project on my own where I’ll be editing roaming ralph in a few different ways. I have a very small amount of knowledge of panda3d, but more significant knowledge of python 2.7. I’m going to try and do most of it on my own with little help from the forums, but I have run into what I hope is a very simple logical problem. I’ve changed the way the camera works (for better or worse), and I’ve run into a little problem. I’ve taken out all of the code that affects the camera, and have replaced it with this.

 base.camera.setPos(self.ralph, 0, 10, 10)
        base.camera.lookAt(self.ralph)

pretty simple, but this gives the result of placing the camera behind ralph, looking down at the back of his head. The camera follows ralph, and stays behind him like i’d like, but I’m trying to angle the camera upwards. When I use this:

 base.camera.setHpr(0,10,0)

or any variation of setHpr, it just makes the camera look directly behind him. Any ideas on what I’m doing wrong? Or is there a better way to get the camera to stay above and behind ralph, while staying with him, and always looking forward with him?

Also, eventually i’m going to try and add weapons/targetting system to this, so if you can think of a way to fix this, that won’t cause problems later with camera movement, that’s a bonus, but really i’m such a beginner it probably will be a while till I’m at that point. Thanks in advance.

I think that the problem is simply that you’re not setting the camera’s orientation (its HPR) relative to Ralph’s; as a result, you’re getting an orientation independant of where Ralph is and what direction he’s facing. When you set the camera’s position, passing in Ralph’s NodePath to the “setPos” call should instruct Panda to set the camera’s position relative to Ralph; similarly, calling “setHpr(self.ralph, 0, 10, 0)” should provide an orientation relative to Ralph’s.

As to other ways to go about it, you could simply parent the camera to Ralph (“base.camera.reparentTo(self.ralph)”), which means that any position and orientation that you set would automatically be relative to Ralph’s (unless you specify otherwise). Whether or not this is a good idea depends, I think, on what you want to do with the camera – if, for example, you want to smooth the camera’s movement reparenting it as I’ve described above may make doing so a little less easy.

Good luck, and have fun! :slight_smile:

Thanks, that helps. I have to do something a little odd to make it work, but I’ve got it doing what I want. After I used base.camera.reparentTo(self.ralph), I also had to change the base.camera.setHpr(0,180,180) since the camera will still facing backwards, away from ralph. Thanks for your help!