3 Replies Latest reply on May 4, 2006 3:31 PM by Newsgroup_User

    Director crash when running collision detection code

    gemmytots
      Hi, I wonder can anyone help!

      Using tutorials from the UNSW, I am creating collison detection using the following code.

      I am using a collision list to gather all the items I want to be classed as rigid. However I am unsure if my code is working at all because my director crashes. The movement code works fine, but not when I add the rest. My W3D file does have a considerable amount of models.

      I would really appreciate if anyone could shed light!

      Gemma
        • 1. Re: Director crash when running collision detection code
          gemmytots Level 1
          I meant to add this in at the ned of the script!

          on characterMove

          -- if the right arrow is pressed,
          -- rotate the character 5 degrees about the z-axis
          if pRightArrow then pCharacter.rotate(0,0,-10)

          variable use before assigned a value

          --if the right arrow is pressed,
          -- rotate character -5 degrees about the z-axis
          if pLeftArrow then pCharacter.rotate(0,0,10)

          -- if the up arrow is pressed,
          -- move the character 5 pixels along the y-axis
          if pUpArrow then pCharacter.translate(0,10,0)

          -- if the down arrow is pressed,
          -- move the character -5 pixels along the y-axis
          if pDownArrow then pCharacter.translate(0,-10,0)

          end

          When trying to save this error appears:

          if pRightArrow then pCharacter.rotate(0,0,-10)

          variable use before assigned a value
          • 2. Re: Director crash when running collision detection code
            Level 7
            "crash when running collision detection code'"

            How ironic!!!

            You should try posting this the 3d group....


            "gemmytots" <webforumsuser@macromedia.com> wrote in message
            news:e362ov$60d$1@forums.macromedia.com...
            > Hi, I wonder can anyone help!
            >
            > Using tutorials from the UNSW, I am creating collison detection using the
            > following code.
            >
            > I am using a collision list to gather all the items I want to be classed
            > as
            > rigid. However I am unsure if my code is working at all because my
            > director
            > crashes. The movement code works fine, but not when I add the rest. My
            > W3D
            > file does have a considerable amount of models.
            >
            > I would really appreciate if anyone could shed light!
            >
            > Gemma
            >
            > -- reference character's bounding box
            > property pCharBoundingBox
            > -- create properties for when arrow keys are pressed
            > -- properties will either be TRUE or FALSE values
            > property pLeftArrow, pRightArrow, pDownArrow, pUpArrow
            >
            > property p3Dmember -- reference to 3D cast member
            > property pSprite -- referebce to the 3D sprite
            > property pCharacter -- reference to the character in the 3D world
            >
            > global flag
            >
            >
            > on beginSprite me
            >
            >
            >
            > -- initiate properties and 3D world
            > pSprite = sprite(me.spriteNum)
            > p3Dmember = sprite(me.spriteNum).member
            > p3Dmember.resetWorld()
            >
            > pCharacter = p3Dmember.model("character")
            > -- we must define pCharacter after we use the resetWorld() command
            > -- otherwise this variable object will be deleted
            >
            > createLight
            > setUpCamera
            > createCharacterBoundingBox
            > -- register the member for regular timeMS events in
            > -- order to respond to user input and resolve camera
            > -- collisions i.e. after specified time segments
            > -- activate collisionDetect handler
            > p3Dmember.registerForEvent(#timeMS,#collisionDetect,me,1000,10,0)
            > end
            >
            > on createCharacterBoundingBox
            >
            > -- create modelResource
            > charModRes = \
            > p3Dmember.newModelResource("charModRes",#box)
            > charModRes.height = 20
            > charModRes.width = 20
            > charModRes.length = 20
            >
            > -- create model and reference to it
            > pCharBoundingBox = \
            > p3Dmember.newModel("CharBoundingBox",charModRes)
            >
            > pCharBoundingBox.worldPosition = \
            > pCharacter.worldPosition
            > pCharacter.addChild(pCharBoundingBox, \
            > #preserveWorld)
            >
            > boxShader = \
            > p3Dmember.newShader("transparentShad",#standard)
            > boxShader.transparent = TRUE
            >
            > -- set opacity of shader 0 is invisible
            > boxShader.blend = 0
            > pCharBoundingBox.shaderList = \
            > p3Dmember.shader("transparentShad")
            >
            > end
            >
            > on collisionDetect me
            >
            > -- create a list to store collision data created by
            > -- modelsUnderRay and cast ray to left
            > collisionList = \
            > p3Dmember.modelsUnderRay(pCharacter.worldPosition, \
            > -pCharacter.transform.yAxis,#detailed)
            > -- if ray picks up models, then activate
            > -- checkForCollion handler and send the
            > -- collisionList as a parameter
            > if (collisionList.count) then \
            > me.checkForCollision(collisionList[1])
            >
            > -- cast ray to right
            > collisionList = \
            > p3Dmember.modelsUnderRay(pCharacter.worldPosition, \
            > pCharacter.transform.yAxis,#detailed)
            >
            > -- if ray picks up models, then check for collision
            > if (collisionList.count) then \
            > me.checkForCollision(collisionList[1])
            >
            > -- cast ray forward
            > collisionList = \
            > p3Dmember.modelsUnderRay(pCharacter.worldPosition, \
            > pCharacter.transform.xAxis,#detailed)
            >
            > -- if ray picks up models, then check for collision
            > if (collisionList.count) then \
            > me.checkForCollision(collisionList[1])
            >
            > -- cast ray backward
            > collisionList = \
            > p3Dmember.modelsUnderRay(pCharacter.worldPosition, \
            > -pCharacter.transform.xAxis,#detailed)
            >
            > -- if ray picks up models, then check for collision
            > if (collisionList.count) then \
            > me.checkForCollision(collisionList[1])
            >
            > end
            >
            > on checkForCollision me, collisData
            > -- grab the #distance value from the CollisionList
            > dist = collisData.distance
            >
            > -- check if distance is less than bounding box width
            > if (dist < pCharBoundingBox.resource.width/2) then
            >
            > -- get distance of penetration
            > diff = pCharBoundingBox.resource.width/2 - dist
            >
            > -- calculate vector perpendicular to the wall's
            > -- surface to move the character using the
            > -- #isectNormal property
            > tVector = collisData.isectNormal * diff
            >
            > -- move the character in order to resolve the
            > -- collision
            > pCharacter.translate(tVector,#world)
            >
            > end if
            >
            > end
            >
            > on createLight
            >
            > -- create a point 'bulb' type light
            > p3Dmember.newLight("Bulb Light", #point )
            >
            > -- position the light
            > p3Dmember.light("Bulb Light").transform.position = vector(0,0,100)
            >
            > -- Make the character model a parent of the light
            > -- Bulb Light" becomes a child of pCharacter
            > -- This is done so that the light will always move with the character.
            > pCharacter.addChild(p3Dmember.light("Bulb Light"),#preserveParent)
            >
            > end
            >
            > on setUpCamera
            >
            > -- create 2 new cameras
            > frontCam = p3Dmember.newCamera("frontCam")
            > characterCam = p3Dmember.newCamera("characterCam")
            >
            > -- frontCam settings
            > -- set up the camera's vertical viewing angle
            > frontCam.projectionAngle = 15
            >
            > -- position the camera
            > frontCam.transform.position = vector(0, -50, 50)
            >
            > -- set rotation of camera
            > frontCam.transform.rotation = vector(50,0,0)
            >
            > -- characterCam settings
            > -- set postion of the camera to position of the character
            > characterCam.transform.position = pCharacter.transform.position
            >
            > -- set rotation of camera
            > characterCam.transform.rotation = vector(70,0,180)
            >
            > -- move camera up and back
            > characterCam.translate(0,-50,100)
            >
            > -- set the camera of the sprite to the frontCam
            > pSprite.camera = p3Dmember.camera("frontCam")
            >
            > -- make cameras children of the character model
            > pCharacter.addChild(frontCam,#preserveParent)
            > pCharacter.addChild(characterCam,#preserveParent)
            >
            > end
            >
            >
            > on changeCamera
            >
            > -- check the sprites camera and switch
            > if pSprite.camera = p3Dmember.camera("characterCam") then
            > pSprite.camera = p3Dmember.camera("frontCam")
            > else
            > pSprite.camera = p3Dmember.camera("characterCam")
            > end if
            >
            > end
            >
            > on keyDown
            >
            > -- check to see which key has been pressed
            > -- and set the property relating to that key to TRUE
            > if keyPressed(123) then pLeftArrow = TRUE -- 123 = left arrow key
            > if keypressed(124) then pRightArrow = TRUE -- 124 = right arrow key
            > if keypressed(125) then pDownArrow = TRUE -- 125 = down arrow key
            > if keypressed(126) then pUpArrow = TRUE -- 125 = up arrow key
            >
            > -- if 'r' key pressed, return character to starting position
            > if keypressed("r") then resetCharacter
            >
            > -- if 'c' key is pressed, then switch camera
            > if keypressed("c") then changeCamera
            >
            > end
            >
            >
            > on keyUp
            > -- when the arrow keys are released, set the properties to FALSE
            > pLeftArrow = FALSE
            > pRightArrow = FALSE
            > pUpArrow = FALSE
            > pDownArrow = FALSE
            > end
            >
            >
            > on exitFrame
            > characterMove
            > end
            >


            • 3. Re: Director crash when running collision detection code
              Level 7
              You need to narrow down your problem a little, instead of posting 300 lines
              of code... Not too many people are going to help you when you post so much
              irrelevent code. Also, your coding style needs some improvement - when
              calling a function put 'characterMove()' and not 'characterMove' as without
              the parenthesis it looks the same as a variable...


              --
              Dave -
              Adobe Community Expert
              www.blurredistinction.com
              www.macromedia.com/support/forums/team_macromedia/