16 Replies Latest reply on Dec 7, 2010 5:16 PM by Jhon Carlo

    Camera Collision Detection - Is It Possible?

    philhog73 Level 1

      Hi,

       

      I am making a 3D RPG game and I would like to know if it is possible to get collision detection on a camera created in Adobe Director 11.  I have my 3D character running through an underground maze and he detects correctly on the walls of the maze.  However, I also have a camera as a child to the character so this moves with him.  I have added a bounding-box to this camera but it still doesn't detect whereas the gunBB works fine, as does the characterBB.

       

      This is really confusing and I don't know what I am doing wrong.  Any help would be really appreciated!

       

      Thanks, Phil.

        • 1. Re: Camera Collision Detection - Is It Possible?
          James Newton, ACP Level 3

          Are you looking for something like this?

          First-person and third-person cameras

          1 person found this helpful
          • 2. Re: Camera Collision Detection - Is It Possible?
            philhog73 Level 1

            Thanks for the reply.  It is not exactly what I am looking for as the script is different than the style I am using.  This is the script I have got so far, I have also added an extra camera to view what is happening.

             

             

             

            property pSprite, p3Dmember -- reference to the 3D member

            --property pLevel, maze -- Level

            --property pLeftArrow, pRightArrow, pDownArrow, pUpArrow -- arrow keys

            --property pCharacter -- character in the 3D world

            --property pTofuBB, pGunBB, gun --  character + gun

            --property gUseGun, hasGun

            --property pCamera, pCameraBoundingBox --camera and bounding box

            --property barrier,mountains,exitmaze

            --property door1, door2, turret, turretgun

            --property keylist, keypresslist -- for keys pressed

            --

            --on beginSprite me

            -- 

            --  -- define the 3D cast member

            --  p3Dmember = sprite(me.spriteNum).member

            -- 

            --  -- reset the 3D world

            --  p3Dmember.resetWorld()

            --  pSprite = sprite(me.spriteNum)

            --  pCamera = pSprite.camera

            -- 

            --  -- define level as 3DS level Plane - must all be defined after resetWorld()

            --  pLevel = p3Dmember.model("landscape")

            --  mountains = p3Dmember.model("mountains")

            --  turret = p3Dmember.model("turret")

            --  turretgun = p3Dmember.model("turretgun")

            --  maze = p3Dmember.model("maze")

            --  exitmaze = p3Dmember.model("exitmaze")

            --  pCharacter = p3Dmember.model("hero")

            --  gun = p3Dmember.model("gun")

            --  barrier = p3Dmember.model("barrier")

            --  door1 = p3Dmember.model("door1")

            --  door2 = p3Dmember.model("door2")

            -- 

            --  -- stop hero walking biped animation

            --  pCharacter.bonesPlayer.pause()

            -- 

            --  -- below for key control

            --  keylist = []

            --  keypresslist = []

            -- 

            -- 

            --  -- this sets up a list of keycodes to track.

            --  -- this code covers the arrow keys only, it could be changed to cover a full range of keys

            --  repeat with i = 123 to 126

            --    keylist[i] = i -- this creates a list of keycodes to track

            --    keypresslist[i] = 0 -- this creates a "last state" list that corresponds to the keycode.

            --   

            --    --keypresslist tracks the last known state of that key, so we can tell when a keypress has changed.

            --  end repeat

            --  -- key control end

            -- 

            --  createBoundingBoxes

            -- 

            --   

            --  createLight

            -- 

            --end

            --

            -- code used to create bounding boxes

            --

            --on createBoundingBoxes

            -- 

            --  -- create tofu bounding box for character

            --  tofuBB_MR = p3Dmember.newModelResource("tofuBox",#box)

            --  tofuBB_MR.height = 235

            --  tofuBB_MR.width = 235

            --  tofuBB_MR.length = 500

            -- 

            --  pTofuBB = p3Dmember.newModel("tofuBox",tofuBB_MR)

            -- 

            --  pTofuBB.worldPosition = pCharacter.worldPosition

            -- 

            --  -- create parent child relationships

            --  pCharacter.addChild(pTofuBB, #preserveWorld)

            -- 

            --  invisShader = p3Dmember.newShader("invisShader",#standard)

            --  invisShader.transparent = TRUE

            --  invisShader.blend = 50

            --  pTofuBB.shaderlist = p3Dmember.shader("invisShader")

            --  --------------------------------------------------------

            --  pCamera = p3Dmember.newCamera("camera")

            --  frontCam = p3Dmember.newCamera("frontCam")

            --  frontCam.fieldOfView = 35

            --  frontCam.transform.position = vector(-14150,-3100,-600)

            --  frontCam.transform.rotation = vector(90,0,180)

            --  pSprite.camera = p3Dmember.camera("frontCam")

            --  pCamera.fieldOfView = 75

            --  pCamera.transform.position = vector(500,1800,450) --450

            --  pCamera.transform.rotation = vector(90,0,180)

            --  pSprite.camera = p3Dmember.camera("camera")

            --  cameraModRes = p3Dmember.newModelResource("cameraModRes",#sphere)

            --  cameraModRes.radius = 200

            -- 

            --  pCameraBoundingBox = p3Dmember.newModel("CameraBoundingBox",cameraModRes)

            --  pCameraBoundingBox.worldPosition = pCamera.worldPosition

            --  pCameraBoundingBox.shaderList = p3Dmember.shader("invisShader")

            --  pCamera.addChild(pCameraBoundingBox, #preserveWorld)

            --  pCharacter.addChild(pCamera,#preserveWorld)

            -- 

            --  --------------------------------------------------------

            -- 

            --  -- create gun bounding box

            --  gun.worldposition.z = gun.worldposition.z + 200

            -- 

            --  gunMR = p3Dmember.newModelResource("gunSphere",#sphere)

            --  gunMR.radius = 218

            -- 

            --  pGunBB = p3Dmember.newModel("gunSphere", gunMR)

            -- 

            --  pGunBB.worldPosition = gun.worldPosition

            -- 

            --  pGunBB.shaderList = p3Dmember.shader("invisShader")

            --  pGunBB.addChild(gun, #preserveWorld)

            -- 

            --end

            --

            --

            -- code below used to light up level

            --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)

            -- 

            --  -- define light color and intensity

            --  p3Dmember.light("Bulb Light").color = rgb(255,255,255)

            -- 

            --  -- 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 keyUp me

            -- 

            --  --pCharacter.bonesPlayer.pause()

            -- 

            --  --if keypressed("s")

            -- 

            --end

            --

            --on keydown me

            -- 

            --  if keypressed("c") then changeCamera

            -- 

            --end

            --

            --on changeCamera

            -- 

            --  -- check the sprites camera and switch

            --  if pSprite.camera = p3Dmember.camera("frontCam") then

            --     pSprite.camera = p3Dmember.camera("camera")

            --     else

            --     pSprite.camera = p3Dmember.camera("frontcam")

            --     end if

            --

            --end

            --on exitFrame me

            --

            -- below detects which keys are pressed

            --

            --repeat with i = 1 to keylist.count

            --inewstate= keypressed( keylist[i] )

            --

            --if keypresslist[i] <> inewstate then -- this means the key changed status from whether it's up or down

            --if inewstate= 0 then

            -- they key was released

            --keyLastReleased = keylist[i]

            --if (keyLastReleased=123) then pLeftArrow = 0 -- 123 = left arrow key

            --if (keyLastReleased=124) then pRightArrow = 0 -- 124 = right arrow key

            --if (keyLastReleased=125) then

            --pDownArrow = 0 -- 125 = down arrow key

            --pCharacter.bonesPlayer.pause()

            --end if

            --if (keyLastReleased=126) then

            --pUpArrow = 0 -- 126 = up arrow key

            --pCharacter.bonesPlayer.pause()

            --end if

            --

            --else

            -- the key was pressed

            --keyLastPressed = keylist[i]

            --if (keyLastPressed=123) then pLeftArrow = 1 -- 123 = left arrow key

            --if (keyLastPressed=124) then pRightArrow = 1 -- 124 = right arrow key

            --if (keyLastPressed=125) then pDownArrow = 1 -- 125 = down arrow key

            --if (keyLastPressed=126) then pUpArrow = 1 -- 126 = up arrow key

            --

            --end if

            --

            --keypresslist[i] = inewstate-- update so we remember its new state.

            --end if

            --end repeat

            --

            -- by the time this repeat loop has finished, keypresslist will contain a complete index of what keys

            -- are held down, and which aren't.

            -- Note: most keyboards have a limit on how many keys they'll track simultaneously.

            --

            --checkCollisions

            --

            --characterMove

            --

            -- gun collision start

            --

            --if gUseGun = TRUE then

            --pTofuBB.addChild(pGunBB,#preserveParent)

            --pGunBB.worldPosition = pTofuBB.worldPosition

            --pGunBB.worldPosition.z = 500

            --pGunBB.worldPosition.x = pCharacter.worldPosition.x - 150 --50

            ---pGunBB.worldPosition.y = -860

            --pGunBB.rotate(0,0,-240)

            --pCharacter.bonesPlayer.pause()

            --gUseGun = FALSE

            --hasGun = TRUE

            --end if

            -- gun collision end

            --

            --end

            --

            --on characterMove

            --

            -- if the right arrow is pressed,

            -- rotate the character 5 degrees about the z-axis

            --if pRightArrow then

            -- rotate character and camera

            --pCharacter.rotate(0,0,-2)

            --end if

            --

            --if the left arrow is pressed,

            -- rotate character -5 degrees about the z-axis

            --if pLeftArrow then

            --pCharacter.rotate(0,0,2)

            --end if

            --

            -- if the up arrow is pressed,

            -- move the character 5 pixels along the y-axis

            --if pUpArrow then

            --

            --if (pcharacter.bonesPlayer.playing = 0) then

            --pCharacter.bonesplayer.loop = true

            --

            --if (_key.shiftDown) then

            --pCharacter.bonesPlayer.playRate = 2

            --

            --if (hasGun = TRUE) then -- running

            --pCharacter.bonesplayer.play("hero", 1, 6270, 8330, 1)

            --else

            --pCharacter.bonesplayer.play("hero", 1, 2067, 4130, 1)

            --end if

            --

            --else

            --pCharacter.bonesPlayer.playRate = 1

            --

            --if (hasGun = TRUE) then -- walking

            --pCharacter.bonesplayer.play("hero", 1, 4200, 6200, 1)

            --else

            --pCharacter.bonesplayer.play("hero", 1, 0, 2000, 1)

            --end if

            --

            --end if

            --

            --end if -- bonesPlayer playing

            --

            --if (_key.shiftDown) then

            --pCharacter.translate(120,0,0)

            --else

            --pCharacter.translate(50,0,0)

            --end if

            --

            --end if

            --

            -- if the down arrow is pressed,

            -- move the character -5 pixels along the y-axis

            --if pDownArrow then

            --

            --if (pcharacter.bonesPlayer.playing = 0) then

            --pCharacter.bonesplayer.loop = true

            --if (_key.shiftDown) then

            --pCharacter.bonesPlayer.playRate = 2

            --

            --if (hasGun = TRUE) then -- running

            --pCharacter.bonesplayer.play("hero", 1, 6270, 8330, 1)

            --else

            --pCharacter.bonesplayer.play("hero", 1, 2067, 4130, 1)

            --end if

            --

            --else

            --pCharacter.bonesPlayer.playRate = 1

            --

            --if (hasGun = TRUE) then -- walking

            --pCharacter.bonesplayer.play("hero", 1, 4200, 6200, 1)

            --else

            --pCharacter.bonesplayer.play("hero", 1, 0, 2000, 1)

            --end if

            --

            --end if

            --

            --end if -- bonesPlayer playing

            --

            --if (_key.shiftDown) then

            --pCharacter.translate(-120,0,0)

            --else

            --pCharacter.translate(-50,0,0)

            --end if

            --

            --end if

            --

            -- floor collision

            --

            --thisPosn = pTofuBB.worldPosition

            -----thisPosn.z = 1000

            --

            --tModelList = [pLevel, maze, door1, door2] -- removed wall as its no longer on level

            --tOptionsList = [#levelOfDetail: #detailed, #modelList: tModelList]

            --

            --thisData = p3Dmember.modelsUnderRay(thisPosn,vector(0,0,-1),tOptionsList)

            --

            --if thisData.count then

            --

            --totalCount = thisData.count

            --repeat with dataIndex = 1 to totalCount

            --

            --terrainPosn = thisData[dataIndex].isectPosition

            --

            --- if (thisData[dataIndex].model = pLevel) then

            --tDiff = (terrainPosn.z - pTofuBB.worldPosition.z) + 375

            --pCharacter.translate(0,0,tDiff,#world)

            --exit repeat

            --

            --end repeat

            --end if

            --end

            --

            --on checkCollisions

            --

            --tModelList = [pGunBB, barrier, mountains, maze, exitmaze, turret, turretgun]

            --tOptionsList = [#maxNumberOfModels: 2, #levelOfDetail: #detailed, #modelList: tModelList, #maxDistance: 300]

            --

            -- make 4 rays around character checking for collisions, 90 degrees apart

            --

            --repeat with i = 1 to 18

            --pCharacter.rotate(0,0,20,#self)

            --

            --returnData = p3Dmember.modelsUnderRay(pCharacter.worldPosition,pCharacter.transform.xAxis,tOptionsList )

            --

            --if (returnData.count) then

            -- first in array is closest

            --checkObjectFoundDistance(returnData[1])

            --end if

            --

            --end repeat

            --

            --end

            --

            --on checkObjectFoundDistance thisData -- check distance from collision with objects

            --

            --dist = thisData.distance

            --

            -- check if distance is less than width of bounding box

            --if (dist < 150) then

            --case thisData[#model].name of

            --"gunSphere":

            --gUseGun = TRUE

            --"barrier":

            -- get distance of penetration

            --diff = 150 - dist

            --

            -- calculate vector perpend icular to the wall's surface to move the character

            -- using the #isectNormal property

            --tVector = thisData.isectNormal * diff

            --

            -- move the character in order to resolve the collision

            --pCharacter.translate(tVector,#world)

            --end case

            --end if

            --

            --if (dist < 150) then

            --case thisData[#model].name of

            --"gunSphere":

            --gUseGun = TRUE

            --"mountains":

            -- get distance of penetration

            --diff = 150 - dist

            --

            -- calculate vector perpend icular to the wall's surface to move the character

            -- using the #isectNormal property

            --tVector = thisData.isectNormal * diff

            --

            -- move the character in order to resolve the collision

            --pCharacter.translate(tVector,#world)

            --end case

            --end if

            --

            --if (dist < 150) then

            --case thisData[#model].name of

            --"gunSphere":

            --gUseGun = TRUE

            --"maze":

            -- get distance of penetration

            --diff = 150 - dist

            --

            -- calculate vector perpend icular to the wall's surface to move the character

            -- using the #isectNormal property

            --tVector = thisData.isectNormal * diff

            --

            -- move the character in order to resolve the collision

            --pCharacter.translate(tVector,#world)

            --end case

            --end if

            --

            --if (dist < 150) then

            --case thisData[#model].name of

            --"gunSphere":

            --gUseGun = TRUE

            --"exitmaze":

            -- get distance of penetration

            --diff = 150 - dist

            --

            -- calculate vector perpend icular to the wall's surface to move the character

            -- using the #isectNormal property

            --tVector = thisData.isectNormal * diff

            --

            -- move the character in order to resolve the collision

            --pCharacter.translate(tVector,#world)

            --end case

            --end if

            --

            --if (dist < 150) then

            --case thisData[#model].name of

            --"gunSphere":

            --gUseGun = TRUE

            --"turret":

            -- get distance of penetration

            --diff = 150 - dist

            --

            -- calculate vector perpend icular to the wall's surface to move the character

            -- using the #isectNormal property

            --tVector = thisData.isectNormal * diff

            --

            -- move the character in order to resolve the collision

            --pCharacter.translate(tVector,#world)

            --end case

            --end if

            --

            --if (dist < 150) then

            --case thisData[#model].name of

            --"gunSphere":

            --gUseGun = TRUE

            --"turretgun":

            -- get distance of penetration

            --diff = 150 - dist

            --

            -- calculate vector perpend icular to the wall's surface to move the character

            -- using the #isectNormal property

            --tVector = thisData.isectNormal * diff

            --

            -- move the character in order to resolve the collision

            --pCharacter.translate(tVector,#world)

            --end case

            --end if

            --end

            --

            • 3. Re: Camera Collision Detection - Is It Possible?
              Jhon Carlo Level 1

              Hello philhog73,

               

              sorry  for my personal question, my bad english and if I reply with question to your question.

              You are expert of Director to much more then me so I ask you an hint cause I find a little about Physx end Director.

              I need to dectect a collision between two body in a 3d scene animate with Phisx and then  make a simple condition:

               

               

              If body A collide with body B then ...

               

               

              I have the w3d with physics collision collision but I don't know wich syntax use to dectect the collision.

               

              Sorry again queston, for me it is to much important.

               

              Thank you very much.

              • 4. Re: Camera Collision Detection - Is It Possible?
                lupuss Level 1

                Hi,

                 

                as I am not exactly specializing in 3D, I would recommend you to check out

                 

                http://www.deansdirectortutorials.com/3D/Havok/

                    or put your question into the Director forum at

                http://director-online.com/forums/list.php?3

                 

                Yours,

                Robert

                 

                 

                **********************************

                • O.Univ. Prof. Dr. Robert Wolff *

                • Fon: +43 (512) 936 759         *

                • Handy: 0699/81341265           *

                • Fax: +43-820-901-187237        *

                • wolff@moz.ac.at                *

                • http://robertwolff.eu          *

                **********************************

                 

                 

                am 07.12.10 09:31 schrieb Jhon Carlo unter forums@adobe.com:

                 

                 

                Hello philhog73,

                 

                sorry  for my personal question, my bad english and if I reply with question

                to your question.

                You are expert of Director to much more then me so I ask you an hint cause I

                find a little about Physx end Director.

                I need to dectect a collision between two body in a 3d scene animate with

                Phisx and then  make a simple condition:

                 

                 

                If body A collide with body B then ...

                 

                 

                I have the w3d with physics collision collision but I don't know wich syntax

                use to dectect the collision.

                 

                Sorry again queston, for me it is to much important.

                 

                Thank you very much.

                >

                • 5. Re: Camera Collision Detection - Is It Possible?
                  philhog73 Level 1

                  Hi Jhon Carlo,

                   

                  I am by no means an expert and am still learning just like you.  I agree with the previous post, check out http://www.deansdirectortutorials.com/ and under "Shockwave 3D" you will find "Collision Detection" and "Collision Detection2".  These are some of the best Director tutorials on the web.  I used the collision detection 2 method as it uses ray-cast but that is entirely up to you.  Good luck anyway.

                   

                  Phil.

                  • 6. Re: Camera Collision Detection - Is It Possible?
                    Jhon Carlo Level 1

                    Thank you veri much for your reply.

                    I go to study the tutoriall!

                    • 7. Re: Camera Collision Detection - Is It Possible?
                      Jhon Carlo Level 1

                      Thanks also to Phil!

                      • 8. Re: Camera Collision Detection - Is It Possible?
                        James Newton, ACP Level 3

                        Perhaps you will find this >draft of a help article< helpful.

                        It describes how to use collision callbacks with the Ageia Dynamiks xtra.

                        Tags marked <SD ...> will send you to the appropriate entry in the Scripting Dictionary.

                         

                        I would appreciate any feedback from you.  Thanks in advance.

                        • 9. Re: Camera Collision Detection - Is It Possible?
                          philhog73 Level 1

                          I have seen this one before but it doesn't deal with the issues I am currently attempting to solve.  I need a door opening by proximity of my character at the minute.  I have used a pause script so it stays shut, just needs opening now, lol.  I have changed my approach to the problem now as it could be a problem with the normals of the maze when I built it in 3DS Max, even though the texture is on the inner maze walls.  Because I am not sure why it behaves like this (everything outside detects), I am now trying to open the door using the proximity of my character which also triggers a camera.transform, so with the character and camera in the same area it will not go out of bounds.

                           

                          Thanks,

                           

                          Phil.

                          • 10. Re: Camera Collision Detection - Is It Possible?
                            James Newton, ACP Level 3

                            You wrote:

                            > I have seen this one before ...

                             

                            Please lend me your time machine :-)

                             

                            The >draft of a help article< for which I provided a link was posted just over an hour ago, as a world premiere.

                            It deals with the question that Jhon Carlo asked earlier today:

                             

                            > I need to dectect a collision between two body in a 3d scene animate with Phisx and then make a simple condition:

                            > If body A collide with body B then ...

                            >

                            > I have the w3d with physics collision collision but I don't know wich syntax use to dectect the collision.

                            • 11. Re: Camera Collision Detection - Is It Possible?
                              philhog73 Level 1

                              No, that is the other person, I am the thread above.

                               

                              Thanks,

                               

                              Phil.

                              • 12. Re: Camera Collision Detection - Is It Possible?
                                James Newton, ACP Level 3

                                Phil wrote:

                                > I need a door opening by proximity of my character at the minute.

                                 

                                Perhaps you might like to consider starting a separate thread for each specific question that you have.  This would make the logic of the questions and answers clearer to everyone.

                                • 13. Re: Camera Collision Detection - Is It Possible?
                                  philhog73 Level 1

                                  Yes, sorry, although this was my original thread and I thought you were referring to me.  I am busy at the minute and didn't check who the message was to.  I would start a new thread but I am making progress.

                                   

                                  Thanks,

                                   

                                  Phil.

                                  • 14. Re: Camera Collision Detection - Is It Possible?
                                    Jhon Carlo Level 1

                                    Thank you very much for your kindly reply. I have seen your link it very interesting. I going to study it. I will inform you of my progres.
                                    Thank you again!

                                    • 15. Re: Camera Collision Detection - Is It Possible?
                                      philhog73 Level 1

                                      Hi OpenSpark,

                                       

                                      I appreciate your help and it is a great site but I have followed Deans Director Tutorials for this project and built on that as I was/am a beginner and I do not think I would have been able to integrate the script.  I have seen quite a few of your tutorials/script on here whilst trailing for info and they are really good.  I thought I had seen that ball tut before but it must just have been a similar one.  End of thread.

                                       

                                      Thanks,

                                       

                                      Phil.

                                      • 16. Re: Camera Collision Detection - Is It Possible?
                                        Jhon Carlo Level 1

                                        Hello Openspark,

                                         


                                        (I've post the same question as new thread if you want you can reply me there).

                                         


                                        At the same time that I'm studing the collision I need to understand how can I do to apply mass or restitution to some body created with 3d max and imported in director in w3d format.

                                         

                                        I know how to apply "transform.position", "transform.rotation" to a w3d created with max, 
                                        and how to apply mass and restitution to a object created with lingo, but I dont know how apply mass to a w3d created with max. 
                                        Wich is the sintax?

                                         

                                        Can you give  to me an hint? 
                                        Thank you.