Professional Web Applications Themes

modelUnderRay problems - Macromedia Director 3D

Hi all, I have emailed to this forum a little while ago under the topic 'collision problems' and haven't got a reply, so am trying again. I can't get modelUnderRay to work consistently. Sometimes the collison detection works, sometimes it doesn't. Are there known problems with this Lingo? Thanks Dave...

  1. #1

    Default modelUnderRay problems

    Hi all,

    I have emailed to this forum a little while ago under the topic
    'collision problems' and haven't got a reply, so am trying again.

    I can't get modelUnderRay to work consistently. Sometimes the collison
    detection works, sometimes it doesn't. Are there known problems with
    this Lingo?

    Thanks

    Dave


    'Dave' webforumsuser@macromedia.com Guest

  2. #2

    Default Re:modelUnderRay problems

    Dave wrote:
    I can't get modelUnderRay to work consistently. Sometimes the collison
    detection works, sometimes it doesn't. Are there known problems with
    this Lingo?

    No problems at all.
    Give us more details (what are you trying to do there ?).


    necromanthus webforumsuser@macromedia.com Guest

  3. #3

    Default Re: modelUnderRay problems

    Hi necromanthus,

    I have a car, which I want to move around the environment I have created.
    I have managed to get it to resond to arrow keys and it moves around fine.
    For collision detection, I use modelUndeRay, but as soon as I play my
    movie, the car starts falling through the ground out of my environment and
    it seems to fall down endlessly. Why would this happen?

    In another shockwave 3D world, I got the collision dectection working with
    some of the models in my scene but the car goes through other models.

    Second, I activated the collision detection in my beginSprite handler as
    follows:
    p3Dmember.registerForEvent(#timeMS,#collisionDetec t,me,1000,10,0)
    I have also tried, the following (instead of using the above):
    on exitFrame
    collisionDetect
    end

    However, when I did it this way, I would get error messages saying "Script
    error:Object expected" and referred to the statement
    if (collisionList.count) then me.checkForCollision(collisionList[1])

    Why would the statement work OK using registerForEvent but not if was
    activated the other way?

    I appreciate any help offered. Thanks.

    Dave



    "\"necromanthus\" webforumsuser"macromedia.com wrote:
    > No problems at all.
    > Give us more details (what are you trying to do there ?).
    'Dave' webforumsuser@macromedia.com Guest

  4. #4

    Default Re: modelUnderRay problems

    For that car you need (at least) two RayCasting systems:
    - the FRONT one (to avoid walls and other objects)
    - the DOWN one (to avoid "falling")
    So,each frame you must cast two rays and check up the distance in case of collision.
    A working example you can find here: [url]http://necromanthus.com/Games/ShockWave/heretix.html[/url]
    cheers


    necromanthus webforumsuser@macromedia.com Guest

  5. #5

    Default Re: modelUnderRay problems

    Hi again,

    Is there any reason why you have to cast a ray downwards? If you look at the tutorial:
    [url]http://www.fbe.unsw.edu.au/Learning/Director/3D/environment/collision2.htm[/url]
    it works without the ray going down.

    In your example, do you only have 2 rays, one down and one forward? How do you specify a
    forward ray? I just used the x and z axis as indicated in the above tutorial.

    Thanks for your help so far.


    "\"necromanthus\" webforumsuser"macromedia.com wrote:
    > For that car you need (at least) two RayCasting systems:
    > - the FRONT one (to avoid walls and other objects)
    > - the DOWN one (to avoid "falling")
    > So,each frame you must cast two rays and check up the distance in case of collision.
    > A working example you can find here: [url]http://necromanthus.com/Games/ShockWave/heretix.html[/url]
    > cheers
    'Dave' webforumsuser@macromedia.com Guest

  6. #6

    Default Re: modelUnderRay problems

    DAVE wrote:
    Is there any reason why you have to cast a ray downwards? If you look at the tutorial:
    [url]http://www.fbe.unsw.edu.au/Learning/Director/3D/environment/collision2.htm[/url]
    it works without the ray going down.

    In your example, do you only have 2 rays, one down and one forward? How do you specify a
    forward ray? I just used the x and z axis as indicated in the above tutorial.


    1) There're a lot of situations when is usefull to cast a ray downwards (for example,in case of irregular floors)
    2) There's no need to use registerForEvent
    3) Here's a nice example (from maze-magic tutorial).
    It is about 4 directions RayCasting system (very usefull for games).

    on mUpdatePosition(me, direction)
    -- if the direction is
    case direction of
    #left:
    -- cast a ray to the left
    result = castRay(w, vector(-1,0,0), w.model("camBox"), 1, #detailed)
    #right:
    -- cast a ray to the right
    result = castRay(w, vector(1,0,0), w.model("camBox"), 1, #detailed)
    #up:
    -- cast a ray to the front
    result = castRay(w, vector(0,0,-1), w.model("camBox"), 1, #detailed)
    #down:
    -- cast a ray to the back
    result = castRay(w, vector(0,0,1), w.model("camBox"), 1, #detailed)
    end case
    if result.count > 0 then
    -- if the ray hit something
    tRes = result[1]
    -- store the model that was hit in the variable tRes
    if tRes.distance < 10 then
    -- if the distance to the model that the ray hit is less than ten units
    RETURN 0
    -- answer FALSE, NOT ok to move
    else
    -- the distance is greater than ten units
    RETURN 1
    -- answer TRUE, ok to move
    end if
    else
    -- the ray didn't hit anything
    RETURN 1
    -- amswer TRUE, ok to move
    end if
    end

    on castRay(whichWorld, whichDirection, whichModel, howMany, detail)
    -- set the variable m to = a reference to the model
    m = whichModel
    -- set the variable wp to = the world relative position of the model
    wp = m.getWorldTransform().position
    -- set the variable md to = the model relative direction
    md = whichDirection
    -- set the variable wd to = the world relative direction
    wd = ( m.getWorldTransform() * md ) - wp
    -- cast the actual ray and return the result
    tCollisions = whichWorld.ModelsUnderRay(wp, wd, howMany, detail)
    return tCollisions
    end


    I hope it helps.
    cheers


    necromanthus webforumsuser@macromedia.com Guest

  7. #7

    Default Re: modelUnderRay problems

    Thanks for all that. I will try the new code and see how it works.
    I still don't know why I couldn't get my code working without using registerForEvent.

    Everything you've offered is very much appreciated.

    "\"necromanthus\" webforumsuser"macromedia.com wrote:
    > DAVE wrote:
    > Is there any reason why you have to cast a ray downwards? If you look at the tutorial:
    > [url]http://www.fbe.unsw.edu.au/Learning/Director/3D/environment/collision2.htm[/url]
    > it works without the ray going down.
    >
    > In your example, do you only have 2 rays, one down and one forward? How do you specify a
    > forward ray? I just used the x and z axis as indicated in the above tutorial.
    >
    > 1) There're a lot of situations when is usefull to cast a ray downwards (for example,in case of irregular floors)
    > 2) There's no need to use registerForEvent
    > 3) Here's a nice example (from maze-magic tutorial).
    > It is about 4 directions RayCasting system (very usefull for games).
    >
    > on mUpdatePosition(me, direction)
    > -- if the direction is
    > case direction of
    > #left:
    > -- cast a ray to the left
    > result = castRay(w, vector(-1,0,0), w.model("camBox"), 1, #detailed)
    > #right:
    > -- cast a ray to the right
    > result = castRay(w, vector(1,0,0), w.model("camBox"), 1, #detailed)
    > #up:
    > -- cast a ray to the front
    > result = castRay(w, vector(0,0,-1), w.model("camBox"), 1, #detailed)
    > #down:
    > -- cast a ray to the back
    > result = castRay(w, vector(0,0,1), w.model("camBox"), 1, #detailed)
    > end case
    > if result.count > 0 then
    > -- if the ray hit something
    > tRes = result[1]
    > -- store the model that was hit in the variable tRes
    > if tRes.distance < 10 then
    > -- if the distance to the model that the ray hit is less than ten units
    > RETURN 0
    > -- answer FALSE, NOT ok to move
    > else
    > -- the distance is greater than ten units
    > RETURN 1
    > -- answer TRUE, ok to move
    > end if
    > else
    > -- the ray didn't hit anything
    > RETURN 1
    > -- amswer TRUE, ok to move
    > end if
    > end
    >
    > on castRay(whichWorld, whichDirection, whichModel, howMany, detail)
    > -- set the variable m to = a reference to the model
    > m = whichModel
    > -- set the variable wp to = the world relative position of the model
    > wp = m.getWorldTransform().position
    > -- set the variable md to = the model relative direction
    > md = whichDirection
    > -- set the variable wd to = the world relative direction
    > wd = ( m.getWorldTransform() * md ) - wp
    > -- cast the actual ray and return the result
    > tCollisions = whichWorld.ModelsUnderRay(wp, wd, howMany, detail)
    > return tCollisions
    > end
    >
    > I hope it helps.
    > cheers
    'Dave' webforumsuser@macromedia.com Guest

Similar Threads

  1. modelunderray list???
    By tacbob in forum Macromedia Director 3D
    Replies: 1
    Last Post: March 6th, 02:45 PM
  2. ModelUnderRay tutorials??
    By tacbob in forum Macromedia Director 3D
    Replies: 1
    Last Post: November 8th, 09:42 PM
  3. modelUnderRay with one ray
    By john_123 in forum Macromedia Director 3D
    Replies: 1
    Last Post: February 6th, 08:19 PM
  4. Help.....Modelunderray
    By baddy in forum Macromedia Director 3D
    Replies: 3
    Last Post: April 4th, 01:14 PM
  5. Replies: 0
    Last Post: September 22nd, 02:18 PM

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