Prof. Monster's Collision script

Hi,

As you know it is difficult to find out with what impact an object collides with an other. This information can be usefull if you want to find out if an object gets destroyed or not.

You could just use the collision sensor, but you might want to keep an object alive that just slipes along an surface. But it should get destroyed on hard impact.

The Collison.py provides you with some methods to do that (2.49b and 2.5x).

The included functions activate all actuators that can perform the tasks you want to see e.g:

  • bullet ends
  • bullet hole added
  • bullet ends and Explosion added (see video)
  • bullet ends lot of shrapnels added (maybe doing teh same thing :wink: )
  • bullet activates a delayed self destruction
  • bullet stucks at the target (ok that one needs a script :D)
    See the Demo file for an example.
    Check this videotutorial to see how to setup the Collision.onSpeedDifference.


A little explaination:
The demo file contains various methods. Not all of them are sufficient, but might come handy for other purposes.

Collision.onSpeedDifference (recommended)
records the last two positions of the bullet
calculates the positional difference (current) between the current and last position
calculates the positional difference (last) between the last and last-last position

activates all actuators when:

  • the current speed is above the value of property “minSpeed” (default 0.1)
  • the ratio (current/last) > value of property “ratio” (default 0.5)
    As this runs with recording as well I tried to avoid an always running script.
    It uses a sensor object to determine if a potential collision might occur. The sensor object should be that large to be able to detect a collision at least 2 frames before the bullet collides (on high speed).

What is the advantage of this method:

  • slow bullets do not activate the actuators (droping from low heigth)

  • sliding bullets do not activate the actuators depending on the “ratio” (sensitivity)
    Problems:

  • a bit more complicated to setup (see video)

  • very fast bullets might collide before the outer sensor object registrates the collision (not handled yet)

  • very fast bullets might crash through a face without loosing to much speed
    Gimick:

  • when you add a property “debug” at the bullet with a value >= 50 it shows you the speed and ratio of a collision. This allows you to set appropriate values for “ratio” and “minSpeed”

Collision.onSpeed

activates all actuators when

  • colliding and
  • the remaining speed is below the value of property"speedLimit"
    See SpeedBullet at layer 2
    Problem is the remaining speed - there is no way to tell what the speed before the collision was.
    Collision.onLostSpeed
    Collision.recordSpeed
    you need both functions
    onRecord records the speed (can be every x frames to increase performance)

onLostSpeed activates all actuators

  • on collision and
  • speed difference below “speedLimit”
    This are two function to avoid running a “heavy” function at every frame

Problem:

  • The interpolation does not work that good
  • The speed difference will quickly be below the speed limit on low speed

Collision.onImpact
This was a try to work with slow parented object to get the last position of the bullet without a python controller. It failed miserably. So forget that one.

Attachments

CollosionSpeedDemo1.blend (49.5 KB)

Thanks Monster! This script is very very helpful and useful!

This is very useful! Thanks for this!

I just dont understand how to use it not as good with scripts as you are for sure lol.

The videotut in the first Post should help you.
Here is a picture of the basic setup as it is in the file:

Attachments