caculate hit damage with velocity ....

i know that getReactionForce() does not work and i have to caculate damage myself.
i use a script to save a object’s velocity every frame. and when the collision happens another script would get the saved velocity and do the caculation.
the problem is i can’t control the order of script running. if i put the caculation script and the velocity saving script on the same object then i can control the execution order by the python controller order in the logic panel. but how to control the order between two objects script ? the damage is according the relative velocity of the two objects and i can’t insure the caculation is done before the two objects’ velocity saving ( or i maybe caculating with the velocity after the collision and that doesnt make sense ).
:eek:

Why use two scripts?

Using the collision sensor’s getHitObject() function (not sure what this is in 2.49), you can access that object’s velocity and then calculate damage based on that. I used this to light up a part of the ground more based on how hard you hit it.

-Sam

well the velocity i got is the velocity AFTER the collision and what i need is the velocity just BEFORE the collision.

When 2.49 comes out you could use the sensor object. Get the list of objects that it detects and save their velocities encase you hit one. Until that release though, you can use the near sensor, which is notably slow if you have to many instances.

2.49 has a new feature: you can mark some controllers to run before any other controllers (the star button). Do this on the controllers that record the velocity and you are certain that the velocities are available when the collision scripts run.

i’m still working with 2.48a and finally i saved 2 frames’ velocity for each object …

SaveVelocity:


from Mathutils import Vector

cCont= GameLogic.getCurrentController()
oObj= cCont.getOwner()

if hasattr( GameLogic, "objData" ) :
    if oObj not in GameLogic.objData :
        GameLogic.objData[oObj]= {}
    data= GameLogic.objData[oObj]
    v= Vector( oObj.getLinearVelocity() )
    if "lastV" not in data :
        data["lastV"]= ( v, v )
    data["lastV"]= ( v, data["lastV"][0] )

get last velocity :


def getLastV( object ) :
    lastVData= GameLogic.objData[object]["lastV"]
    if Vector( object.getLinearVelocity() ) != lastVData[0] :
        return lastVData[0]
    else :
        return lastVData[1]