Is it possible to access data from a collision, such as point of collision and impact force? I am trying to simulate a "drop test" in Blender and cannot figure out how to access the information. As of now, I am trying to use the Blender game engine and python.
1 Answer
$\begingroup$
$\endgroup$
3
By using collision callbacks you can retrieve the hit object, point and normal (not sure about how to retrieve the impact force though). See the API reference for more info. Example file below.
def my_callback(object, point, normal):
''' Do whatever you want with your collision data '''
print('Hit by', object.name, 'at', point, 'with normal', normal)
def register_callback(cont):
''' Run this with an always sensor (tap enabled) when the game starts '''
own = cont.owner
if not my_callback in own.collisionCallbacks:
own.collisionCallbacks.append(my_callback)
Example file:
-
$\begingroup$ Thank you! Do you know how to run this code while the game engine is running? $\endgroup$ Commented May 24, 2019 at 17:30
-
$\begingroup$ @RussellChow I've added a better script and a example file (for Blender 2.79). If this answers your question, please accept the answer. ;) $\endgroup$ Commented May 25, 2019 at 3:16
-
$\begingroup$ Thank you very much for the help! $\endgroup$ Commented May 27, 2019 at 23:12