Help needed with collision

Ask a Question related to Macromedia Director 3D, Design and Development.

  1. #1

    Default Help needed with collision

    Hey all, i've got a project that needs to simulate a crane moving. Basically,
    i've got the crane all moving and has a box that moves as the load. There are
    objects on the floor, i.e pallettes.

    I have got invisible boxes over these pallettes and use these for the
    collision detection.

    I was using the modelsUnderRay function on the box (load) to detect for
    collisions, but this was not any good as would not detect if the corner of the
    box hit anything.

    At the moment I have got 4 little boxes on the bottom corners which shoot out
    rays, and works very well, but is very CPU intensive as you can imagine.

    I tried using havok, but as the load is in the air, when i make it a moveable
    rigidbody it just falls to the ground.

    Any ideas?

    AndrewNock Guest

  2. Similar Questions and Discussions

    1. 3D: Collision
      Anyone know of a way to do a collision detection (Shockwave 3D) at a particular time. just once. i.e. run some command or set of commands that...
    2. JRE Collision
      Hello all. system developer edition: CF MX7 os: win 2003 java version: 1.5.0_04 default settings for all cf installation options I'm...
    3. if collision then?
      is there any such script? i want to go to a specific frame when my model collides with anotherm is that possible?
    4. collision
      i have imported a 3D scene W3D exported from 3Dmax in the scene i have objects and groups, when i resolve collisions for objects it works fine,...
    5. collision problems
      Hi all, I have been trying to get collision detection working with my shockwave 3D world. Basically, I have a car, which I want to move around...
  3. #2

    Default Re: Help needed with collision

    if you need a proper collision detection, i think the best way would be to go
    with havok and invest some time into getting it to work. If you set up
    everything correct the box should defenitely fall to the ground :)

    Use dashpots or springs to get a grip on the box. you can move the havok
    controlled body only by forces, impulses, springs, dashpots ... take a close
    look in the havok reference, it's worth it.

    to set up a proper box collision with rays you can use a "trick" by sending
    the rays not exactly into the direction of the models axis use vectors like
    "vector(0.0001, 0.9999, 0.0001)" - search the forum for more informations on
    this topic.

    If you go with havok, it would be nice to get some more details about things
    that you want to do, and where you run into problems.

    cheers!

    hondo3000 Guest

  4. #3

    Default Re: Help needed with collision

    Hi, thanks for that. I did spend a little time with havok, making the 'load'
    held by dashpoints, but it was really buggy and ended up going with rayCasting.
    If I get time nearer the end, I will try and have another go...
    The rayCasting works ok on my machine (3ghz 1GB RAM) if I send out plenty of
    rays, but the users machine is a 3ghz with only 256RAM. I will need to test it
    out on theirs before making a decision. Unfort, I can't test it on theirs for a
    while, and am not allowed to post the product up.
    Will look at your 'trick' - do you know of any tutorials that mention it?

    AndrewNock Guest

  5. #4

    Default Re: Help needed with collision

    this is a short version of the "phenomen":
    [url]http://director-online.com/lingo.php?id=578[/url]

    If you want to more optimized raydetection use the propertylist of the ray. in
    this way you can optimize by distance and by a list of models that are checked
    by the ray - think you know this allready... otherwise take a look at the
    livedocs about modelsunderray.

    regards!

    hondo3000 Guest

  6. #5

    Default Re: Help needed with collision

    Hi, thanks for that.

    I have been using an optimized ray but I don't think its doing what it should.
    The options list is as follows:

    -- build your optional argument list
    tOptionsList = [#maxNumberOfModels: 3, #levelOfDetail: #detailed,
    #modelList:tModelList, #maxDistance: 5]

    And am calling this in the 'controlCollision' function.

    tPosition = dB.worldPosition
    tDirection = -(dB.getworldtransform().xaxis)
    tDirection.normalize()
    tList = p3DMember.modelsUnderRay(tPosition,tDirection,tOpt ionsList)
    if (tList.count) then
    me.checkForCollision(tList[1])
    put ("hi")
    end if


    If I do a 'put ("hi")' in where I have above, it gets called all the time. I
    would have thought this would only be called if an object on the list i
    declared was within 3 of another object. But does not seem the case....

    AndrewNock Guest

  7. #6

    Default Re: Help needed with collision

    Hi Andrew,

    It is possible to achieve very acceptable resutls with modelsUnderRay, and I
    would only advise using havok if you really require a full physics simulation
    (eg, you want tumbling balls and boxes falling in a realistic way or
    something!).

    To align a model to a vector (such as your ray cast vector), you can use
    something like this:

    tiltAngle = vector(0,0,1).anglebetween(theVector)
    tiltVector = theVector.perpendicularto(vector(0,0,1))
    theModel.transform.rotation = vector(0,0,0)
    theModel.transform.rotate(rayBeam.transform.positi on,tiltVector,-tiltAngle)

    To align it to a ray vector, and display it correctly, if your model was a
    'box' from director's default box primitive, you would then want to position it
    halfway between the ray cast source, and the ray intersect position (because
    the box's origin is in its centre), and scale it so that it extends the full
    distance between the two.

    Luckily this is actually a frequently asked question, and something that I do
    quite a lot myself - so I happen to have some demo movies showing it in action!

    First here's some roughly compiled information about modelsUnderRay(), mostly
    advice I've given out on various director mailing lists in the past:


    [url]http://www.robotduck.com/content/articles/director/collision/modelsUnderRay/mode[/url]
    lsUnderRay.txt

    And here are a few demos of how it can be used effectively (including one with
    visible beams as you described!)


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


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


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


    [url]http://www.robotduck.com/content/articles/director/collision/modelsUnderRay/wall[/url]
    Collision_V-Ray.htm


    [url]http://www.robotduck.com/content/articles/director/collision/modelsUnderRay/wall[/url]
    Collision_V-Ray_visibleBeams.htm



    Enjoy!


    - Ben





    duckets Guest

  8. #7

    Default Re: Help needed with collision

    fist of all, you will only need: #maxNumberOfModels: 1, this will make anything
    three times faster.

    maybe you should "put tList" instead of "put "hi" to check if the list is
    really empty.

    May I ask how big your models are? you should use for best results words where
    100 units are 1m. This will make all calculations more precise because the 3D
    engine has a fixed floatprecision of 4.
    At the moment i think the #maxdistance property has something to do with the
    "boundingsphere". Maybe someone here does know how the #maxdistance really
    works. Would make sense if it checks if the models boundingsphere is within a
    given distance before it will process the ray calculation...

    your code seems like it should work?

    regards!

    hondo3000 Guest

  9. #8

    Default Re: Help needed with collision

    whoops, I thought this was the thread about setting objects to make raycasts
    visible - same poster, but different thread! My previous post was mainly to do
    with making rays visible but maybe its relevant to this thread too.

    - ben


    duckets Guest

  10. #9

    Default Re: Help needed with collision

    hondo3000: will have maxNumberOfModels: 1 - thanks
    Have tried having tList instead of "hi", but it brought up loads of things
    wayy too quick for me to read and hung my computer.

    I'm not sure how big the world is to be honest. Will ask the person who
    modelled it later.
    The code does work, i'm just wondering why it was bringing stuff on the tList
    all the time rather than when something is close to it.

    Duckets: Thanks for those examples, and you helped in both posts with the same
    example. I'm gonna have a go at implementing this on monday and will let u
    know how I get on.

    For now, have a good weekend

    AndrewNock Guest

  11. #10

    Default Re: Help needed with collision

    Hey duckets, thanks for that code. Got it working on the crane and is great.
    Really good to actually see where the rays are going!
    One issue I do have is regarding the direction. i.e.

    tDirection1 = dA.transform.yAxis (dA is a block i am shooting ray from).

    When I rotate the group this block is on, it keeps shooting the same way, and
    not the new rotated direction. What am I doing wrong?
    e..g If I set it to shoot towards me, then turn the load, it keeps shooting
    towards me.

    AndrewNock Guest

  12. #11

    Default Re: Help needed with collision

    the ray origin and the ray vector aren't inherently tied to any particular
    object - so rotating an object won't affect where a ray is shooting from.

    If you're calculating your ray's vector from dA's rotation, you'll probably
    need to get it's 'world transform' as opposed to its local transform. If you're
    rotating an object up the hierarchy from dA (eg, its parent group), then
    although dA moves as a result, its own local transform values won't actually
    change. Its world transform will though. You can get an object's world
    transform like this:

    worldXform = dA.getWorldTransform()

    hope this helps.

    - Ben


    duckets Guest

  13. #12

    Default Re: Help needed with collision

    Hi thanks for that. Kinda get what you mean. How would I get just the Y value though. I used the line you said and its shooting the rays down, but not out in the direction I want.
    AndrewNock Guest

  14. #13

    Default Re: Help needed with collision

    Don't worry, got a way of doing it.

    tPositionA = dA.worldPosition
    tPositionB = dB.worldPosition
    tPositionC = dC.worldPosition
    tPositionD = dD.worldPosition

    tDirection1 = -(tPositionB - tPositionA)
    tDirection2 = -(tPositionB - tPositionC)

    Got the world positions and used them to get the vector.

    Cheers anyway, hope this works better. An thanks again for the code to show
    the rays, help soooo much!

    AndrewNock Guest

Posting Permissions

  • You may not post new threads
  • You may 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