I found some code by Social that calculates impact forces. I have integrated it into a script I am currently working on but I have come across a problem. To start with here is the code:
def collision(cn): ow = cn.owner collision = cn.sensors["collision"] if collision.positive: linv_now = ow.getLinearVelocity() applied_vec = linv_now - ow["linv_before"] print ("For object:", ow.name) print ("--Impact magnitude:", applied_vec.magnitude) applied_vec.normalize() print ("--Direction vector:", applied_vec.magnitude) print ("") # Space #ow["health"] -= ???? < what to put here? else: ow["linv_before"] = ow.getLinearVelocity() print(ow["linv_before"].magnitude)
Now when my objects collide with anything this script outputs the force of the collision. The thing is, I would love to use this number so it can be subtracted from the objects health property (in the line I annotated with ???). I have tried a couple of approaches but I get a ‘cannot use with noneType’ error so I am guessing I need to convert it somehow…
Can anyone give me some pointers?