Professional Web Applications Themes

Models Under Ray Collision - Macromedia Director 3D

Basically I have a simple 3D scene with unlevel terrain and a character (3DSMax Teapot!!) which I want to follow the terrain. I have set up the movement script separately and created a collisionDetection script using modelsUnderRay. problem is that my character floats away. it transforms position off in some strange almost vertical angle in time with the delay set in registerForEvent.... Anyone seen this before or have any ideas?? Here's the script code anyways.. property pCharBoundingBox property p3Dmember property pCharacter property collisionList property pSprite property pTarget ------------------------------------- ------------------------------------- on beginSprite me -- initiate properties and 3D world pSprite = ...

  1. #1

    Default Models Under Ray Collision

    Basically I have a simple 3D scene with unlevel terrain and a character (3DSMax
    Teapot!!) which I want to follow the terrain. I have set up the movement
    script separately and created a collisionDetection script using modelsUnderRay.
    problem is that my character floats away. it transforms position off in some
    strange almost vertical angle in time with the delay set in
    registerForEvent.... Anyone seen this before or have any ideas?? Here's the
    script code anyways..



    property pCharBoundingBox
    property p3Dmember
    property pCharacter
    property collisionList
    property pSprite
    property pTarget
    -------------------------------------
    -------------------------------------
    on beginSprite me

    -- initiate properties and 3D world
    pSprite = sprite(me.spriteNum)
    p3Dmember = sprite(me.spriteNum).member

    pCharacter = p3Dmember.model(pTarget)

    createCharacterBoundingBox

    p3Dmember.registerForEvent(#timeMS,#collisionDetec t,me,1000,200,0)

    end
    -------------------------------------
    -------------------------------------
    on createCharacterBoundingBox

    -- create model resource
    charModRes = p3Dmember.newModelresource("charModRes",#box)
    charModRes.height = 20
    charModRes.width = 34
    charModRes.length = 15

    -- create model and reference to it
    pCharBoundingBox = p3Dmember.newModel("CharBoundingBox",charModRes)

    pCharBoundingBox.worldPosition = pCharacter.worldPosition
    pCharBoundingBox.translate(0,0,7)
    pCharacter.addChild(pCharBoundingBox, #preserveWorld)

    boxShader = p3Dmember.newShader("transparentShad",#standard)
    boxShader.transparent = TRUE

    -- set opacity of shader 0 is invisible
    boxShader.blend = 50
    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(pCharBoundingBox.worldPos ition,
    -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(pCharBoundingBox.worldPos ition,
    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(pCharBoundingBox.worldPos ition,
    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(pCharBoundingBox.worldPos ition,
    -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 getPropertyDescriptionList(aScript)

    tGPDList = [:]

    tGPDList[#pTarget] = \
    [#comment:"Character to apply collision detection to (3D
    Character)",\
    #format: #String,\
    #default: "none"]

    return(tGPDList)

    end getPropertyDescriptionList

    Urbley04 Guest

  2. #2

    Default Re: Models Under Ray Collision

    Don't have time to read through your script (most people will ignore a request
    for help with a large script attached!), but I have a few demos of how I do
    terrain following with modelsUnderRay:

    Ground height detection using models under ray:

    http://www.robotduck.com/content/articles/director/collision/modelsUnderRay/grou
    ndCollision.htm


    Ground alignment using models under ray: [www.robotduck.com]

    http://www.robotduck.com/content/articles/director/collision/modelsUnderRay/grou
    ndCollisionAndAlign.htm

    Smooth interpolation of ground alignment using modelsUnderRay:

    http://www.robotduck.com/content/articles/director/collision/modelsUnderRay/grou
    ndCollisionAndAlignInterpolated.htm

    hope these help!

    - Ben



    duckets Guest

  3. #3

    Default Re: Models Under Ray Collision

    thats right, the script is a bit too long...

    but i think this line is will make the problem:
    tVector = collisData.isectNormal * diff

    maybe you change the code to something like this:
    diff = pCharBoundingBox.resource.width/2
    tVector = collisData.isectposition + diff

    pCharacter.transform.position=tVector

    but this is only from my head, but i think you should put in some "put"
    commands to monitor what's going on with the vectors.


    but this is just

    hondo3000 Guest

  4. #4

    Default Re: Models Under Ray Collision

    Thanks people.. But I think I may take the havok approach this time. I was having serious errors cropping up when adding the inserted havoks physics scene but I'll work around it.
    Urbley04 Guest

  5. #5

    Default Re: Models Under Ray Collision

    wow ben those demos looks awsome, how come i never saw those in the site?
    Pyro-ct Guest

  6. #6

    Default Re: Models Under Ray Collision

    Because they're part of a new load of demos which I have thrown together over
    the course of the last few years but I haven't had time to write up on the site!

    Here's a rough and ready directory navigator which you can use to browse
    what's there at the moment:

    http://robotduck.com/content/articles/director/dirlist.php

    enjoy!

    - Ben


    duckets Guest

  7. #7

    Default Re: Models Under Ray Collision

    hi Bob,

    im a bit of newbie to all this. im currently doing my dissertation using
    Lingo. im creating a 3D maze which contain a tutorial within it. i.e. source
    code given to a user at certain checkpoints. i was looking at your wall
    collision detection demo's and was wondering can it be done in first person
    view as i have not implemented an object into the shockwave. if at all possible
    can you let me know, im kinda slowing down on my dissertation. i have the maze
    up and running though

    thanks
    Farhan

    Farhan Guest

  8. #8

    Default Re: Models Under Ray Collision

    sorry, i ment Ben not bob.
    Farhan Guest

  9. #9

    Default Re: Models Under Ray Collision


    Like this?

    http://robotduck.com/content/articles/director/collision/modelsUnderRay/wallCollision_V-Ray-FPS.htm

    enjoy!

    - Ben

    duckets Guest

  10. #10

    Default Re: Models Under Ray Collision

    hi ben,

    sorry for the late reply. yeah its what i was talking about. thats going to help. you wouldn't mind if i look at your code and use anything i can, would you?

    Farhan
    Farhan Guest

  11. #11

    Default Re: Models Under Ray Collision

    Not at all, that's what it's there for :-)

    - Ben

    duckets Guest

  12. #12

    Default Re: Models Under Ray Collision

    Hey Ben,

    those links of yours are just great (as usual), I'm a moderator on the main
    french Director forum : can I spread those links on the forum for other users
    to see/learn ? Or do you prefer having them all "cleaned" first like the ones
    available on your website ?
    Many of our users don't speak/understand english at all so they never get on
    the mailing lists or english forums like this one.

    Thanks

    Matse Guest

  13. #13

    Default Re: Models Under Ray Collision

    Hi Matse,

    Sure, feel free to spread the links, they are public. I'm not sure what you
    mean by 'cleaned' though? I guess perhaps you mean that there's no written
    tutorial page to go with them... don't worry, when I add those I will do it in
    such a way that the links don't break.

    - Ben


    duckets Guest

Similar Threads

  1. 3D: Collision
    By cj-22 in forum Macromedia Director 3D
    Replies: 2
    Last Post: March 27th, 10:43 AM
  2. JRE Collision
    By BornOnBoard in forum Coldfusion Server Administration
    Replies: 0
    Last Post: September 29th, 08:29 PM
  3. if collision then?
    By Chanizz in forum Macromedia Director 3D
    Replies: 4
    Last Post: June 3rd, 09:02 PM
  4. resolve collision with moving models
    By danredman in forum Macromedia Director 3D
    Replies: 0
    Last Post: September 7th, 09:32 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