5 Replies Latest reply on Jul 6, 2006 7:24 AM by Newsgroup_User

    ModelsUnderRay not working

    AndrewNock
      Hey all,

      I'm moving the load of my crane, with a bounding box around it. This moves ok with the crane.
      Unfort, using modelsUnderRay, the code will only stop once the building touches the middle of the bounding box, not the outside. How do i fix this?

      Thanks, Andy

      --------
      --LEFT--
      --------
      -- initialize a position and a direction vector
      tPosition = pCharBoundingBox.worldPosition
      --tDirection = pCharBoundingBox.transform.xAxis
      tDirection = pLoad.transform.xAxis

      -- cast the ray
      tList = member("Crane").modelsUnderRay(tPosition, tDirection, tOptionsList)

      -- -- if ray picks up models, then check for collision
      if (tList.count) then me.checkForCollision(tList[1])
        • 1. Re: ModelsUnderRay not working
          ensamblador Level 1
          what is the value of tOptionList?
          • 2. Re: ModelsUnderRay not working
            AndrewNock Level 1
            HI, thanks for the reply, here is the rest of the relevant code...

            -- build your modelList
            tModelList = [member("Crane").model("Ground"),member("Crane").model("Load"), member("Crane").model("Building04"), member("Crane").model("Target01"), member("Crane").model("Obstacle01")]

            -- build your optional argument list
            tOptionsList = [#maxNumberOfModels: 10, #levelOfDetail: #detailed, #modelList:tModelList, #maxDistance: 3]
            • 3. Re: ModelsUnderRay not working
              Roofy Level 1
              quote:

              Originally posted by: AndrewNock
              Hey all,

              I'm moving the load of my crane, with a bounding box around it. This moves ok with the crane.
              Unfort, using modelsUnderRay, the code will only stop once the building touches the middle of the bounding box, not the outside. How do i fix this?

              Thanks, Andy

              2 things...
              1. From my experiemce with modelUnderRay it seem like it checks the model's pivot point. For example say you have a cube where the width is 50 units, length is 100 units, and the height is 10 units, and the pivot point is in the center of the cube. instead of saying this....

              collisData = modelsUnderRay( your settings)
              if collisdata.count then
              dist = collisData[1][4]
              if dist < yourModel.worldPosition then
              your code
              end if


              Instead, you need to build hover offset. Using my cube example, my hover distance would be half of the width, length, or height total units depending on which side you are detecting collision on. So lets say the width side of the cube is colliding with the ground. Now knowing the width of the cube is 50 units then the additional hover offset would be 25 (width of the cube / 2). In other words the code would look somthing like this...

              collisData = modelsUnderRay( my settings)
              if collisdata.count then
              dist = collisData[1][4]
              hoverOffset = myCubeExample.worldPosition + 25
              if dist < hoverOffset then
              my additional code
              end if

              Just note that you cannot get an object's demenions that has been buillt in another 3D application

              2. I never seen using a property list for your arguments with the command modelsUnderRay, so this might also be causing problems as well.
              • 4. Re: ModelsUnderRay not working
                Sumerian
                Hi Andrew,

                When I do models underray, I basically always do it something like this:

                dirns=[vector(0,1,0),vector(1,0,0),vector(0,-1,0),vector(-1,0,0)]
                diam=20 repeat with i=1 to dirns.count
                dog=gmem.modelsunderray(pos,dirns ,1,#detailed)
                if dog.count>0 then
                if dog[1].distance<diam then
                pos=dog[1].isectposition-dirns
                *diam
                --anything facy here
                end if
                end if
                end repeat

                This does the four coordinates (NESW), and you can add top and bottom to the array.

                The "pos" is your vector position, and diam is a chosen distance that you will feel is close enough to your object to be considered a collision.

                It's nice because it does the lot in a onner, the only problem being that modelsunderray has the drawback of your being able to theoretically squeeze yourself through the tiniest gap, and into the wrong place if you're unlucky.

                P.S: Has anybody sorted ouit an equation to use the collision detection? I've tried occasionally, and always ended up back with the ray-cast.

                Cheers,

                James ( gamevial)
                • 5. Re: ModelsUnderRay not working
                  Level 7
                  Sumerian wrote:
                  > When I do models underray, I basically always do it something like
                  > this:
                  >
                  > dirns=[vector(0,1,0),vector(1,0,0),vector(0,-1,0),vector(-1,0,0)]
                  ...

                  About modelsUnderRay aligned with an axis:-
                  http://nuttybar.drama.uga.edu/pipermail/dir3d-l/2005-November/010090.html

                  Andrew (but not that one)