4 Replies Latest reply on Feb 6, 2007 7:05 AM by Nickname_is_none

    Camera moves slowly back to origin

    Nickname_is_none
      I'm moving a camera around in a 3d room. When I move left/right/up/down (using seperate sprites), I want the camera to move back to it's original position (like a piece of elastic).

      Any ideas on how to script this?
        • 1. Re: Camera moves slowly back to origin
          duckets Level 1
          Check out the 'interpolateTo' function. Specifically, you need something like:

          myCam.transform.interpolateTo(originalTransform,80)

          Each time the above line is executed, 'myCam' will move 80 percent of the remaining distance towards 'originalTransform'. originalTransform should be a duplicate of the camera's starting transform.

          hope this helps!


          - Ben
          • 2. Re: Camera moves slowly back to origin
            Nickname_is_none Level 1
            Firstly, thanks for getting back to me.

            I'm having a bit of trouble implementing this.....

            I mousedown on a sprite to move l/r/u/d, when I release the mousebutton I want the camera to move slowly back to where it started.

            In my 3d file (called 'Tube') I have Camera01, Tube01 and Sphere01. I control the camera with seperate sprites with Global scripts.

            An example of this is:

            Sprite behaviour:
            On mousedown me
            gPanLeft = True

            In my 3D Behaviour I have:
            if gPanLeft then pCamera.rotate(-1,0,0)

            From the Duckets example above...

            - I presume I change 'myCam' to 'Camera01'
            - I need to set the 'originalTransform' value, do I do this as a property in 'beginSprite'
            - If I place that code within the 3D behaviour, do I need to make a global reference to the sprite behaviour? (eg 'if gNoButton then Camera01.transform.interpolateTo(pOriginalTransform,80)

            Or am I totally way off the mark with this!?!?!?!?!?!?!?!?


            • 3. Camera moves slowly back to origin
              duckets Level 1
              quote:

              Originally posted by: Nickname is none
              - I presume I change 'myCam' to 'Camera01'
              - I need to set the 'originalTransform' value, do I do this as a property in 'beginSprite'
              - If I place that code within the 3D behaviour, do I need to make a global reference to the sprite behaviour? (eg 'if gNoButton then Camera01.transform.interpolateTo(pOriginalTransform,80)
              Or am I totally way off the mark with this!?!?!?!?!?!?!?!?



              You're pretty much there. The 'myCam' variable is the equivalent of what you have as 'pCamera'. That is, it's supposed to be a variable in which you have previously placed a reference to your camera, something like this: pCamera = member("tube").camera("camera01"), so you can change the line to:

              pCamera.transform.interpolateTo(pOriginalTransform,80)

              Define 'pOriginalTransform' as a property at the top of your 3d behaviour, and in the beginsprite handler of it, do this:

              pOriginalTransform= pCamera.transform.duplicate()

              And finally, you'll just need to check whether none of your control buttons are being pressed, eg:

              if not (gPanLeft or gPanRight or gPanUp or gPanDown) then
              pCamera.transform.interpolateTo(pOriginalTransform,80)
              end if

              hope this sorts it out for you,

              - Ben

              • 4. Re: Camera moves slowly back to origin
                Nickname_is_none Level 1
                That is perfect!!!! I've changed the speed to 1 to slow it down a bit.

                You're a genius, thanks!!!!