Professional Web Applications Themes

isometric game style cameras - Macromedia Director 3D

Hi there Im trying to a make a sometric style game ive set up the camera's iso height and projection and made the camera the child of the moving object but when i rotate my object the camera rotates also. I dont want it to, i just want it to follow the object. does anyone know how to do it. subterenia...

  1. #1

    Default isometric game style cameras

    Hi there
    Im trying to a make a sometric style game ive set up the camera's iso height
    and projection and made the camera the child of the moving object but when i rotate my object the camera rotates also.

    I dont want it to, i just want it to follow the object.
    does anyone know how to do it.

    subterenia



    subterenia webforumsuser@macromedia.com Guest

  2. #2

    Default Re: isometric game style cameras

    What is your object rotation relative to ? The world (#world) or the object
    itself (#self) ?



    Karl Sigiscar Guest

  3. #3

    Default Re: isometric game style cameras

    hi karl
    I think its to the #world

    subterenia


    subterenia webforumsuser@macromedia.com Guest

  4. #4

    Default Re: isometric game style cameras

    Just make the camera pos equal the object pos plus an offset Vector. Eg. . .

    property offSetVector,cam
    on beginSprite
    offSetVector = vector(100,100,100)-- Or whatever you need
    cam = sprite(1).camera
    end beginSprite

    on exitFrame
    cam.worldPosition = member("3DScene").model("myModel").worldPosition + offSetVector
    end exitFrame

    This will position the camera correctly, but avoid it rotating with the object.

    Rix


    Rix webforumsuser@macromedia.com Guest

  5. #5

    Default Re: isometric game style cameras

    Thanks Rix

    Ill give it a try and I'll let you no if it works.

    subterenia


    subterenia webforumsuser@macromedia.com Guest

  6. #6

    Default Re: isometric game style cameras

    Hi Rix
    it didnt work.
    the code seemed ok (there where no script errors)
    so im thinking that maybe I did something wrong.
    thanks anyway Rix.

    subterenia


    subterenia webforumsuser@macromedia.com Guest

  7. #7

    Default Re: isometric game style cameras

    Hi Rix

    The reason why your code did not work, could have something to do with the
    script that im using to control the car, if your feeling charitable
    have a look at the script

    nice one Rix

    -------------------------------------------------------------------------------
    --Summary----------------------------------------------------------------------
    -------------------------------------------------------------------------------




    --------------------------------------------------------------------------------
    --Properties--------------------------------------------------------------------
    --------------------------------------------------------------------------------
    --Author Defined Properties
    -----------------------------------
    property pModel -- Model. Which model(s) of the scene to drag.
    property pMaxSpeed -- See parameter description below
    property pMaxTurnSpeed
    property pAccGain
    property pDecGain
    property pBrakeGain
    property pTurnGain
    property pGrip
    property pForward
    property pTurnAxis
    property pDrag


    -----------------------------------
    --General Properties
    -----------------------------------
    property pCamera --------- Camera. This sprite's camera.
    property pMember --------- Member. The member of this sprite.
    property pSprite --------- Sprite. This sprite.
    property pHavok

    property pGoingForward
    property pGoingBackward
    property pGoingLeft
    property pGoingRight
    property pBraking

    --------------------------------------------------------------------------------
    --Sprite Handlers---------------------------------------------------------------
    --------------------------------------------------------------------------------
    on beginSprite(me)

    pSprite = sprite(me.spriteNum)
    pHavok = pSprite.pHavok
    pMember = pSprite.member
    pCamera = pSprite.camera

    if voidP(pModel) then pModel = pMember.model[1].name

    pGoingForward = false
    pGoingBackward = false
    pGoingLeft = false
    pGoingRight = false
    pBraking = false

    -- Set the friction quite low - we want the controller below to handle most of the car motion
    -- rb = pHavok.rigidBody( pModel )
    -- rb.friction = 0.01
    end beginSprite


    -----------------------------------
    --PURPOSE: General clean up.
    --ACCEPTS: 'me' as an instance of this script.
    --RETURNS: Nothing.
    -----------------------------------
    on endSprite(me)

    end endSprite

    -----------------------------------
    --PURPOSE: Poll the keyboard to alter driving behaviour
    --ACCEPTS: 'me' as an instance of this script.
    --RETURNS: Sets internal properties
    -----------------------------------
    on getKeys(me)

    pGoingForward = keyPressed(126)
    pGoingBackward = keyPressed(125)
    pGoingRight = keyPressed(124)
    pGoingLeft = keyPressed(123)
    pBraking = keyPressed(" ")

    end getKeys

    -------------------------------------------------------------------------------
    --PURPOSE: Applied the required forces to drive the vehicle
    --
    --ACCEPTS: 'me' as an instance of this script.
    --RETURNS: Nothing.
    -----------------------------
    on driveController(me)

    -- Transform forward and axis vectors into world space
    trans = pMember.model(pModel).transform.duplicate()
    if (trans.position.z > 20) then
    return
    end if

    trans.position = Vector(0,0,0)
    trans.scale = Vector(1,1,1)

    currentFwd = trans * pForward
    currentAxis = trans * pTurnAxis
    currentRight = currentFwd.cross(currentAxis)

    -- Commonly used physical information
    rb = pHavok.rigidBody( pModel )
    currentVel = rb.linearVelocity -- Current Velocity
    currentSpeed = currentVel.dot(currentFwd) -- Magnitude of velocity in the forward direction
    propSpeed = min(abs(currentSpeed) / pMaxSpeed , 1) -- Forward velocity as a proportion of max speed
    angularVel = rb.angularVelocity -- Ask Havok for the angular velocity
    mass = rb.mass -- Ask Havok for the mass

    -- If going forward we want to reach our Max Speed
    if (pGoingForward) then
    diff = pMaxSpeed - currentSpeed
    -- Apply an impulse proportial to the difference
    -- between our desired speed and our actual speed
    imp = (diff * pAccGain * mass) * currentFwd
    rb.applyImpulse( imp )
    end if

    -- If reversing we reach -Max Speed
    if (pGoingBackward) then
    diff = -pMaxSpeed - currentSpeed
    -- Apply an impulse proportial to the difference
    -- between our desired speed and our actual speed
    imp = (diff * pDecGain * mass) * currentFwd
    rb.applyImpulse( imp )
    end if

    -- If braking we reach 0
    if (pBraking) then
    imp = (-currentSpeed * pBrakeGain * mass) * currentFwd
    rb.applyImpulse( imp )
    end if

    -- Check if we can turn.
    -- We check if the magnitude of our angular velocity is less than our max turn speed
    -- Max Turning speed depends on velocity
    mTS = min(abs(currentSpeed), (1.0 - propSpeed ) * pMaxTurnSpeed)
    canTurn = (abs(angularVel.dot(currentAxis)) < mTS)

    -- If we can turn and we're turning left
    if (canTurn and pGoingLeft) then
    -- Apply an angular impulse to turn us left
    imp = currentAxis * (pTurnGain * mass)
    if( pGoingBackward ) then imp = -imp
    rb.applyAngularImpulse( imp )
    end if

    -- If we can turn and we're turning right
    if (canTurn and pGoingRight) then
    -- Apply an angular impulse to turn us right
    imp = currentAxis * (-pTurnGain * mass)
    if( pGoingBackward ) then imp = -imp
    rb.applyAngularImpulse( imp )
    end if

    -- Work out how fast we're sliding left/right
    -- An compensate according to the grip property
    -- We just allow the car to slide if its braking
    slideSpeed = currentRight.dot(currentVel)
    if not (pBraking) then
    imp = currentRight * (-slideSpeed * mass * pGrip)
    -- Apply an impulse to compensate for sliding
    rb.applyImpulse( imp )
    end if

    -- Apply an angular impulse to compensate for spinning
    if (canTurn=false) or ((pGoingLeft=false) and (pGoingRight=false)) then
    imp = currentAxis * angularVel.dot(currentAxis) * (-pTurnGain * mass)
    rb.applyAngularImpulse( imp )
    end if

    -- Apply Drag proportional to speed
    imp = -currentVel * (pDrag * mass)
    rb.applyImpulse( imp )

    end driveController

    -------------------------------------------------------------------------------
    --PURPOSE: Applied the required forces to drive the vehicle
    --
    --ACCEPTS: 'me' as an instance of this script.
    --RETURNS: Nothing.
    -----------------------------
    on enterFrame(me)

    -- Check the keys and set the state variables
    me.getKeys()

    -- Apply the controller to drive the vehicle
    me.driveController()

    end enterFrame


    --------------------------------------------------------------------------------
    --Predefined Handlers-----------------------------------------------------------
    --------------------------------------------------------------------------------
    --PURPOSE: Determines whether the behavior can be dropped onto a sprite in the score.
    --ACCEPTS: 'aScript' as a reference to a script member.
    -- 'aSpriteType' as a symbol. It indicates the type of sprite attempting
    -- to be dropped on to.
    -- 'aSpriteNum' as an integer. Indicates the channel of the sprite being
    -- dropped on to.
    --RETURNS: True if the behavior is allowed to be dropped on the sprite or score,
    -- false otherwise.
    -----------------------------------
    on isOKtoAttach(aScript, aSpriteType, aSpriteNum)

    case aSpriteType of
    #Graphic:
    case sprite(aSpriteNum).member.type of
    #shockwave3d:
    if aScript.getModels(sprite(aSpriteNum).member, []).count > 0 then
    --There exist models to choose from.
    return(TRUE)
    else
    --This is a 3D member that has no models.
    return(FALSE)
    end if

    #text:
    if sprite(aSpriteNum).member.displayMode = #mode3D then
    return(TRUE)
    else
    return(FALSE)
    end if
    end case

    #script:
    return(FALSE)
    end case

    return(FALSE)

    end isOKtoAttach





    -----------------------------------
    --PURPOSE: Allows the user a dialog box access to the behavior's properties.
    --ACCEPTS: 'aScript' as a reference to a script member.
    --RETURNS: 'TGPDList' as a property list containing author definable behavior properties
    -----------------------------------
    on getPropertyDescriptionList(aScript)

    if the currentSpriteNum > 0 then

    tGPDList = [:]

    tList = []
    tList = aScript.getModels(sprite(the currentSpriteNum).member, tList)

    if tList.count > 1 then

    tGPDList[#pModel] = \
    [\
    #comment:"Which model",\
    #format: #string,\
    #range: tList,\
    #default: tList[1]\
    ]
    else
    nothing
    --There is only one model in the member. So, don't offer a selection
    --as to which model to rotate.
    pModel = tList[1]
    end if

    tGPDList[#pMaxSpeed] = \
    [\
    #comment:"Maximum Speed",\
    #format: #float,\
    #default: 500\
    ]

    tGPDList[#pMaxTurnSpeed] = \
    [\
    #comment:"Maximum Turning Speed",\
    #format: #float,\
    #default: 50\
    ]

    tGPDList[#pAccGain] = \
    [\
    #comment:"Acceleration",\
    #format: #float,\
    #default: 0.2\
    ]

    tGPDList[#pDecGain] = \
    [\
    #comment:"Reverse Acceleration",\
    #format: #float,\
    #default: 0.1\
    ]

    tGPDList[#pBrakeGain] = \
    [\
    #comment:"HandBrake Power",\
    #format: #float,\
    #default: 0.2\
    ]

    tGPDList[#pTurnGain] = \
    [\
    #comment:"Turning",\
    #format: #float,\
    #default: 0.02\
    ]

    tGPDList[#pGrip] = \
    [\
    #comment:"Grip",\
    #format: #float,\
    #default: 0.1\
    ]

    tGPDList[#pDrag] = \
    [\
    #comment:"Aerodynamic Drag",\
    #format: #float,\
    #default: 0.02\
    ]

    tGPDList[#pForward] = \
    [\
    #comment:"Local Forward",\
    #format: #vector,\
    #default: Vector(1,0,0)\
    ]

    tGPDList[#pTurnAxis] = \
    [\
    #comment:"Local Rotate",\
    #format: #vector,\
    #default: Vector(0,0,1)\
    ]

    return(tGPDList)

    end if

    end getPropertyDescriptionList


    -----------------------------------
    --PURPOSE: Provides a tooltip in the behavior library palette.
    --ACCEPTS: 'aScript' as a reference to a script member.
    --RETURNS: 'tString' as a string.
    -----------------------------------
    on getBehaviorToolTip(aScript)

    tString1 = "Drive a physical model using the arrow keys" & RETURN & RETURN
    tString2 = "-" && "Type" && ":" && "Local Action" & RETURN
    tString3 = "-" && "Usage" && ":" && "Drop this onto a scene with physics"
    return(tString1 & tString2 & tString3)

    end getBehaviorToolTip


    -----------------------------------
    --PURPOSE: Provides a behavior description in the behavior inspector.
    --ACCEPTS: 'aScript' as a reference to a script member.
    --RETURNS: 'tString' as a string.
    -----------------------------------
    on getBehaviorDescription(aScript)

    tString1 = "DRIVE A PHYSICAL MODEL" & RETURN & RETURN & \
    "Use the arrow keys and space (handbrake) to drive the model." & RETURN & RETURN & \
    "PARAMETERS:" & RETURN & \
    "- Model to be driven" & RETURN & \
    "- Max Speed" & RETURN & \
    "- Max Turn Speed (affects turning circle)" & RETURN & \
    "- Acceleration" & RETURN & \
    "- Reverse Acceleration" & RETURN & \
    "- Handbrake Power" & RETURN & \
    "- Cornering Power" & RETURN & \
    "- Lateral Grip" & RETURN & \
    "- Aerodynamic Drag" & RETURN & \
    "- Forward axis" & RETURN & \
    "- Turning axis" & RETURN & \
    "PERMITTED SPRITE TYPES:" & RETURN & \
    "- Shockwave 3D"
    return(tString1)
    end getBehaviorDescription

    --------------------------------------------------------------------------------
    --General Utilities and Predefined Handler Support------------------------------
    --------------------------------------------------------------------------------
    --PURPOSE: Gets the names of each model in a member.
    --ACCEPTS: 'me' as an instance of this script.
    -- 'aMember' as a member.
    -- 'aList' that will be used to store the names.
    --RETURNS: 'aList' containing the model names.
    -----------------------------------
    on getModels(me, aMember, aList)

    repeat with j = 1 to aMember.model.count
    if string(aMember.model[j]) contains "model" then
    aList.add(aMember.model[j].name)
    end if
    end repeat

    return(aList)

    end getModels



    subterenia webforumsuser@macromedia.com Guest

  8. #8

    Default Re: isometric game style cameras

    Hi Subterenia :)

    The script is so simple theres very little not to work as long as you have referenced your sprite and model correctly. It just applies an offset to the camera relative to the model and points the camera at the model on beginSprite. As long as none of your own code manipulates the camera it should work.

    In what way does it not work ? Just behaves as before ?

    I assume your 3D scene is in sprite 1 slot and youve added the behavior to the 3D sprite ?

    Have you removed your own camera code ?

    Have you removed the code where you parent the camera to the object ?

    Have you applied Havok control to your camera ? I didn't realise you were using Havok. If its a Havok issue I can't help as I always code my own physics.

    I'll do my best to help though, thanks

    Richard




    Rix webforumsuser@macromedia.com Guest

  9. #9

    Default Re: isometric game style cameras

    Hi rix
    Im using a havok object that is controlled by key board input.
    so im not sure if you will be able to help me out, but anyway I really appreciate you having
    a go.

    Nice one rix

    If I don't get the camera working in the next few days I might try a different approach to my
    game.

    all the best subterenia.


    subterenia webforumsuser@macromedia.com Guest

Similar Threads

  1. isometric game design. help required
    By Tony Currie in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: February 10th, 10:54 AM
  2. monopoly style game?
    By NinjaTurtle webforumsuser@macromedia.com in forum Macromedia Director Basics
    Replies: 3
    Last Post: December 1st, 02:30 PM
  3. LocZ probem in isometric game
    By erito141 webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 2
    Last Post: November 24th, 10:52 AM
  4. Help with whack a mole style game
    By KDoggO3 webforumsuser@macromedia.com in forum Macromedia Director Basics
    Replies: 1
    Last Post: October 30th, 02:30 AM
  5. 3D Game DOOM style
    By Devistator webforumsuser@macromedia.com in forum Macromedia Director 3D
    Replies: 0
    Last Post: July 20th, 10:52 AM

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