UPBGE Resource: Randomly generate animated game objects

Randomly generate animated game objects upbge demo.
Objects in the scene can move freely and randomly.
https://www.youtube.com/watch?v=P6FV23u2ID8

cat4

import bge
import random
cont = bge.logic.getCurrentController()
own = cont.owner
sens = cont.sensors['Collision']

Action_walk = cont.actuators['Action_walk']
Action_sit = cont.actuators['Action_sit'] 


rotate_choice = [ [0,0,1.571],[0,0,-1.571],[0,0,3.142] ,[0,0,0] ]
Dtime = bge.logic.getClockTime()
action_choice = ["move","move","wait"]


local=True
change_action = int(Dtime%own["time"])==0
if  own["action"] and change_action:

    random_rotate = random.choice(rotate_choice)
    own.applyRotation(random_rotate ,local)
    
    own["action_type"] = random.choice(action_choice)
    own["time"] = random.randint(4,8)
    
    
else:
    if own["action_type"] =="move":
        own.applyMovement([0,0.1*own.get("speed",1),0],local)
        cont.activate(Action_walk)
    if own["action_type"] =="wait":
        cont.activate(Action_sit)

if sens.positive:
    random_rotate = random.choice(rotate_choice)
    own.applyRotation(random_rotate ,local)
    own["action_type"] =="move"
        

if change_action :
    own["action"]=False
else :
    own["action"]=True

You can download the project source files (for upbge 0.3+)here to support me:

1 Like