1
$\begingroup$

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.

$\endgroup$
2
$\begingroup$

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)

enter image description here

Example file:

$\endgroup$
  • $\begingroup$ Thank you! Do you know how to run this code while the game engine is running? $\endgroup$ – Russell Chow May 24 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$ – Joel Gomes da Silva May 25 at 3:16
  • $\begingroup$ Thank you very much for the help! $\endgroup$ – Russell Chow May 27 at 23:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.