Adjusting Camera angles/Positions

So in my program I want the camera to be able to point at certain objects at the user’s request. I’ve got the camera positions working with etc…, but unfortunately the camera angles don’t seem to be working, even though I am calculating values and calling the function, the camera itself doesn’t seem to want to change its angle. Any work-arounds/tips?

full code including where I work out the angles here:

  def cameraTask(self,task):
        if self.trackedObject !=None:
            a = self.trackedObject.getTrackPos()
            angleXYZ = self.getAxisAngles(self.trackedObject)
  [0], angleXYZ[1], angleXYZ[2])

    def getAxisAngles(self, obj):
        angleXYZ = []
        camera_pos =
        objectPos = obj.getPos()
        cam_obj_vector = Vector(camera_pos[0] - objectPos[0], camera_pos[1] - objectPos[1], camera_pos[2] - objectPos[2])
        cam_obj_vector_list = cam_obj_vector.getVectorList()
        for i in range(3):

            cos_angle_camToObj = cam_obj_vector_list[i]/(cam_obj_vector.getSpeed())
            angleCamToObj = math.degrees(math.acos(cos_angle_camToObj))
        return angleXYZ

Is it something to do with the getPos function I’m using to get the camera position?

I feel like the isn’t recommended, purely because when I print that value out it eternally says 0, so idk if there is another function with similar purpose or not

My first question is this: What results are you seeing from “self.trackedObject.getTrackPos()”? If you print out its values (i.e. “a” in your first method above), what do you see?

Based on what I’m seeing there, your use of “getPos” should work; thus I suspect that the problem is elsewhere.

That said, however, let me point you to Panda’s “lookAt” and “headsUp” suites of methods, which might make your life rather easier!

(Just beware, in case you aren’t already, that you aren’t setting the camera’s position to be the same as that of the target object!)

Hey, in the past I’ve tried lookAt and it doesn’t really seem to work:/

I’ve called camera.lookAt(loader object but it doesn’t seem to do anything. But thank you for the suggestion. Not really sure what went wrong, but I’ll have to stick to manually pointing the camera, which isn’t the end of the world! :slight_smile:

Sorry, I have to ask a strange question… You have disabled the mouse… e control of the camera node?


1 Like

Ah, yeah, that’s a good point–if the default mouse-control hasn’t been disabled, then none of this camera-positioning is going to work properly, I daresay!

If you have disabled the default mouse-control, then this is odd. Do you have anything else controlling the camera’s orientation, and that might be interfering with “lookAt”?

What is “loader object”…?