Director 3D > Collision Detection


Here are some general tips for the creation of collision detection in your 3D applications:

  • Collision detection must be included in your plans from the very beginning of a project – the very structure of the project depends on it. In general, there 3 areas of collision detection: the collision modifier; your own custom solution; and the havok xtra. Buidling your own solution is the best option in terms of speed. The best way of going about this is to consult Paul Catanese’s book, “Director’s Third Dimension” (Que, 2002)
  • It is important that the models you use for collisions do not include intersecting geometry—that is, two models that overlap each other. However, models that touch and are grouped will handle collisions cleanly.
  • The use of the collision modifier is useful for relatively simple applications only. It can be very processor intensive, especially if there are complex models and a large number of modifiers attached to objects.
  • For body physics you should turn to the Havok Xtra, which is included with Director.
  • There is another way of creating code for collision detection - using the modelsUnderRay command.This involves casting rays from the camera in 4 directions - forward, backward, left and to the right. For each ray cast, we would have to verify if the distance to the nearest model exceeded the camera's bounding sphere radius. If the distance is less than the bounding sphere's radius, you would then move the camera out of the collision state in a direction perpendicular to the intersected model's surface. The modelsUnderRay command returns a list of models found under the ray. The syntax is as follows:

    member(whichCastmember).modelsUnderRay(locationVector, directionVector, \ {maxNumberOfModels, levelOfDetail}) maxNumberOfModels and levelOfDetail are optional parameters.

< Previous | Next >

July 2003