Professional Web Applications Themes

camera rotation limits not right - Macromedia Director 3D

I have a camera rotating left/right/up/down, I am trying to limit the rotation to 150 degrees in any direction. I have this code working for the left/right: if gPanLeft then pCamera.rotate(0,1,0) pCamera.transform.rotation.z = max(-150, min(150,pCamera.transform.rotation.z)) I'm using the same code for up/down (using the x axis), but the camera stops about 50 degrees in the up direction and about 210 in the downwards direction. I thought I might have a problem with the starting angle of my camera (as saved from 3DS Max) and I have tried using different angles to compensate, but they don't seem to do much. I ...

  1. #1

    Default camera rotation limits not right

    I have a camera rotating left/right/up/down, I am trying to limit the rotation
    to 150 degrees in any direction.

    I have this code working for the left/right:

    if gPanLeft then pCamera.rotate(0,1,0)
    pCamera.transform.rotation.z = max(-150,
    min(150,pCamera.transform.rotation.z))

    I'm using the same code for up/down (using the x axis), but the camera stops
    about 50 degrees in the up direction and about 210 in the downwards direction.

    I thought I might have a problem with the starting angle of my camera (as
    saved from 3DS Max) and I have tried using different angles to compensate, but
    they don't seem to do much. I have also checked to see if my camera collision
    is stopping the rotation, but it isn't.

    Can anyone help?

    Nickname Guest

  2. Moderated Post

    Default Re: camera rotation limits not right

    Removed by Administrator
    Richard Guest
    Moderated Post

  3. #3

    Default Re: camera rotation limits not right

    Thanks for the response, and for shedding some light on what the problem might
    be.

    I'll give that code a test and let you know if it works. I'll have to play
    around with it as my camera slowly swings back to it's origin when the mouse
    button is released.

    Thanks.

    Nickname Guest

  4. #4

    Default Re: camera rotation limits not right

    Right, not having much luck.

    I understand the priniciple of this, but I can't intergrate it with the rest
    of my code. I keep getting a script error: "variable used before assigned a
    value", when I set my properties on a beginsprite.

    In the beginsprite script, as well as the script you described above, I also:
    _initiate properties of the pSprite, p3Dmember, pCamera
    _create the camera's bounding sphere
    _make the sphere a child of the camera
    _register events for camera collision detection
    _origin
    _ the movement script above

    For the rest of my lingo, I have the camera coliision script, script to move
    the camera back to it's origin, and the movement script that you also mentioned
    above.

    Any clues as to the holes in my wafer-thin lingo skills?

    Nickname Guest

  5. #5

    Default Re: camera rotation limits not right

    Hi,

    Can you get the rotation limit script to work on its own (just get the
    camera rotating left and right with limits)? I can't really help with all
    the other scripts without seeing them and knowing what you are trying to
    achieve. Do all the scripts you mention work correctly before you added the
    rotation limit script?

    You need to narrow down where that 'variable used before assigned a value'
    error is coming from, usually a typo for a property name, or failure to add
    a property to the property declaration at the top of the script, or failure
    to initialize a variable before using it's value in a statement.

    Be aware that the register for collision lingo functions are very unreliable
    and slow, and I personally never use it. A radial distance check and ray
    casting are usually better options.

    Maybe if you describe your project in detail I may be able to suggest
    something.

    Cheers :)

    Richard Smith


    Richard Guest

  6. #6

    Default Re: camera rotation limits not right

    I did get the script working by itself, then I didnt....it seems to be causing
    problems when it reaches it's 150 limit then stops the other directions working.

    Using you're script above, to then move right, I have used:
    if gPanRight AND pCamRotY < 150 then
    pCamRotY = pCamRotY - 1
    end if

    I thought that the degree restriction should then be -150, but that stops it
    working. I have the same issues for the Up/Down.

    As for the actual project, it is a effectively a scope camera in a tunnel that
    I want pivot around (like a worm).

    Nickname Guest

  7. #7

    Default Re: camera rotation limits not right

    Hi there,
     

    OK, it seems to be you have a simple logic error. This is the type of thing
    you need...
    ----------------------
    if gPanRight AND pCamRotY < 150 then
    pCamRotY = pCamRotY+1
    end if

    if gPanLeft AND pCamRotY > -150 then
    pCamRotY = pCamRotY-1
    end if
    -----------------------

    Note the use of 'greater than' with the negative value comparison. Use this
    pattern for the X and Y axis, Z is usually left alone. If the camera works,
    but the keys seem reversed, just switch the plus and minus signs in the
    'body' of each if statement.


    Please note I will not be around for the next 4 days (in case you think I'm
    ignoring posts). Cheers :)

    Richard Smith


    Richard Guest

  8. #8

    Default Re: camera rotation limits not right

    Ahhhhhh, must've been the only thing I didn't try!!! Thanks.

    It seems to working well, thanks for your help.

    I'm going to try and add the other bits (zooming, and an automatic slow
    'return to origin').

    Nickname Guest

  9. #9

    Default Re: camera rotation limits not right

    Ok, the next step that I can't get working is to make the camera slowly move
    back to it's origin if none of the movement buttons are pressed. So far I
    have...

    if not (gPanLeft or gPanRight or gPanUp or gPanDown or gZoomIn or gZoomOut)
    then pCamera.transform.interpolateTo(pOriginalTransform ,1)

    Rather than using pCamera, should I be using the pCamRotX, pCamRotY, pCamRotZ
    route? Or is there a totally different/better way that I should be doing this?

    Nickname Guest

  10. #10

    Default Re: camera rotation limits not right

    Hi there,

    if you just want to return the rotation back to (0,0,0) use this sort of
    thing...
    ------------------------------
    if NOT gPanLeft AND NOT gPanRight AND NOT gPanUp AND NOT gPanDown AND NOT
    gZoomIn AND NOT gZoomOut then
    pCamRotX = pCamRotX * 0.95
    pCamRotY = pCamRotY * 0.95
    pCamRotZ = pCamRotZ * 0.95
    pCamera.transform.rotation = vector(pCamRotX,pCamRotY,pCamRotZ)
    end if
    -------------------------------
    Check out how the if logic differed from yours to see why it was locking up.

    For a slower return to center use 0.98 instead of 0.95 etc...

    if the origin you want to return pCamera to is world postion (0,0,0) then
    just do this...
    -----------
    pCamera.worldPosition = pCamera.worldPosition * 0.95
    -----------
    quick and dirty, but gives nice smooth motion return.

    Sorry I took so long to reply, been away.

    Good luck

    Richard Smith


    Richard Guest

  11. #11

    Default Re: camera rotation limits not right

    Brilliant! I've also re-alligned my initial 3DS model to accomodate a 0,0,0
    allignment (it was originally 90,0,0), and it's working perfectly.

    I've got some other amendments to make to my models, but my next step is to
    add a button to stop all movement except the zoom. So I might be back to this
    post, but in the meantime, thanks for your help Mr Smith!!

    Nickname Guest

Similar Threads

  1. reset camera rotation?
    By tacbob in forum Macromedia Director 3D
    Replies: 1
    Last Post: March 9th, 02:44 PM
  2. Camera rotation around an object
    By aperion0 in forum Macromedia Director 3D
    Replies: 0
    Last Post: July 14th, 04:51 AM
  3. Camera rotation
    By de4med in forum Macromedia Director 3D
    Replies: 6
    Last Post: May 6th, 02:52 PM
  4. Please help with camera rotation
    By de4med in forum Macromedia Director 3D
    Replies: 5
    Last Post: October 31st, 08:57 AM
  5. camera limits
    By jdf3971 webforumsuser@macromedia.com in forum Macromedia Director 3D
    Replies: 2
    Last Post: August 14th, 02:38 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139