Zero>
This is my collision code, it simply takes the linear velocity and compares it to before, subtracting any difference from a health value (the multiplier allows me to lessen or worsen collisions). I did have a line that printed the direction of the hit too. I hope it is of some use. At some point I think Blenders physics are going to be able to detect the magnitude of collisions automatically- will be great when it does!Code:def Collision(cn): ow = cn.owner collision = cn.sensors["collision"] collision.propName = "solid" multiplier = 1 if ow["health"] > 0: if collision.positive: linv_now = ow.getLinearVelocity() linv_before = ow.get("linv_before", linv_now) applied_vec = linv_now - linv_before print ("For object:", ow.name) print ("--Impact magnitude:", applied_vec.magnitude) print ("") ow["health"] = ow.get("health", 0.0) - applied_vec.magnitude * multiplier print(str(ow.name) + str(ow["health"])) else: ow["linv_before"] = ow.getLinearVelocity()
Split times are working for me, although sometimes when multiple ships fly across the line it gets confused.




Reply With Quote
