2 Replies Latest reply on Aug 7, 2006 3:21 AM by danieloizo1

    3D character camera control

    JustStupid
      Hi,

      Just had a quick look and don't think this question has been answered before. I'm trying to get my camera to follow a character so the camera being just positioned above and slighly behind and pointed down so you can see whats in front of the character and still see its head. I've been playing around with trying with the addChild method and get the camera to move with the character but when I rotate the character (using the arrow keys) the camera doesn't rotate to show the new view. Does anyone know how this could be achieved? Sample code will be a big bonus!!

      Thanks in advance for any suggestions.

      Brenden
        • 1. Re: 3D character camera control
          JustStupid Level 1
          Update:

          Seem to be able to associate the camera with the character but the camera is not sticking with the character when it moves. Heres the code I have now:

          characterCam = MyWorld.camera[1]
          characterCam.transform.position = character.worldposition + vector (0,0,5)
          characterCam.transform.rotation = vector(90,0,180)
          character.addChild(characterCam)

          Any ideas??
          • 2. Re: 3D character camera control
            danieloizo1
            Hi,

            i made a camera following a character this way:
            1. i made 3 boxes invisible(box1.shader.blend = 0), box1 over the character ,box2 behind the character and box3 is intepolateing to box1

            on exitframe
            characterrotate = character.transform.rotation.z -- characterrotate is a var
            box2.transform.position.y = character.transform.position.y -- character is the moveing character
            box2.transform.position.x = character.transform.position.x -250 --moves box2 250 units behind character
            box2.rotate(0,0,characterrotate,character)

            box1.transform.position.z = character.transform.position.z + 30 -- moves box1 30 units above character
            box1.transform.position.y = character.transform.position.y
            box1.transform.position.x = character.transform.position.x

            camera1.transform.interpolateto(box2.transform,30) --camera interpolates to box 2
            box3.transform.interpolateto(box1.transform,15)
            camera1.pointat(box3, vector(0,0,1)) -- camera points at box 3 witch is interpolateing to box 1
            end

            2. the camera is using "interpolateto" becouse i dont want the camera to be fixed on the box, if the camera is fixed on the box it can result in a "noisy" movement of the camera( the camera may go up and down when the character follows a rough terrain)
            the camera point's at box3 to follow the charater in a more natural manner.

            Now if you move the characterter camera will follow and always point on on him.

            hope i made no mistakes in the script and sorry for my bad english.

            Daniel.