Upbge python code animations and raycast

How do you manage armature animations with python and no logic bricks ?
Same for raycast how can it be done with code and no logic bricks ?
Is there some documentation about using collision detection between two rigibody fully in python code ?

It’s hard to find tutorials, most are mixing code and logic bricks, but i didn’t found tutorials made with python code only covering those topics.

I found how to animate, adding this script to the armature object

    cont = bge.logic.getCurrentController()
    own = cont.owner
    own.playAction('IDLE', 0, 20, layer=0, play_mode=bge.logic.KX_ACTION_MODE_PING_PONG)

I have raycast working


start =  scene.objects['start']
end =  scene.objects['end']

hitObject, hitPosition, hitNormal = own.rayCast(end.worldPosition,start.worldPosition,100)

if hitObject:
    print("Object hit:", hitObject, "at", hitPosition, "the normal at that point is", hitNormal)
    print("hit nothing")

Is missing script how to detect collision between a rigidbody and other physic objects ?

This collision code does not work in Upbge 0.3.
Is there a better way ? Can we get all objects colliding insteda of the first one only ?

cont = bge.logic.getCurrentController()
own = cont.owner

def callback_three(object, point, normal):
print(‘Hit by %r at %s with npormal %s’ % (object.name, point, normal))

def callback_one(object):
print(‘Hit by %r’ % object.name)

def register_callback(controller):

if you need collision contacts, that is the only way to get them (collision callback)

If I get a minute I will make a example or someone else may beat me too it.

if you don’t need the collision contact you can use a logic sensor - collision - to get access to who you are touching but not where.


Both examples would be cool, callback and sensor, python only and no logic bricks :smiley:

so even if you love python,

for python SENSORS are essential

they are basically callbacks for your python


you can run pure python but it’s silly,
logic sensors are basically polling stuff in C
you can’t do the same stuff effectively in py.

1 Like