wind Vs Pinning threshold

add wind object


import bge
from mathutils import Vector


def main():


    cont = bge.logic.getCurrentController()
    own = cont.owner
    
    scene=bge.logic.getCurrentScene()
    added=scene.addObject('Wind',own,360)
    if bge.logic.getRandomFloat()>.5:
        own['X']+=bge.logic.getRandomFloat()
    else:
        own['X']-=bge.logic.getRandomFloat()    
    if own['X']>3:
        own['X']=3
    else:
        if own['X']<-3:
            own['X']=-3
    if bge.logic.getRandomFloat()>.5:
        own['Y']+=bge.logic.getRandomFloat()
    else:
        own['Y']-=bge.logic.getRandomFloat()    
    if own['Y']>15:
        own['Y']=15
    else:
        if own['Y']<0:
            own['Y']=0
    if bge.logic.getRandomFloat()>.5:
        own['Z']+=bge.logic.getRandomFloat()
    else:
        own['Z']-=bge.logic.getRandomFloat()    
    if own['Z']>5:
        own['Z']=5
    else:
        if own['Z']<-5:
            own['Z']=-5  
    Vex=Vector([own['X'],own['Y'],own['Z']])                            
    added['Strength']=Vex


main()



randomly deviate values over time


import bge
from mathutils import Vector


def main():


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


    Vec=Vector(own['Strength'])
    Vec.x*=.95
    if bge.logic.getRandomFloat()>.5:
        Vec.x+=bge.logic.getRandomFloat()*2
    else:
        Vec.x-=bge.logic.getRandomFloat()*2
    Vec.y*=.95
    if bge.logic.getRandomFloat()>.5:
        Vec.y+=bge.logic.getRandomFloat()*2
    else:
        Vec.y-=bge.logic.getRandomFloat()*2
    Vec.y=abs(Vec.y)    
    Vec.z*=.95
    if bge.logic.getRandomFloat()>.5:
        Vec.z+=bge.logic.getRandomFloat()*2
    else:
        Vec.z-=bge.logic.getRandomFloat()*2                
    own['Strength']=Vec
    own['read']=str(Vec.magnitude)
main()



apply wind and break pinning if over threshold


import bge




def main():


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


    sens = cont.sensors['Collision']
    


    if sens.positive and own['Strength']!="Empty":
        vex=own['Strength']
        Vmag=vex.magnitude
        print(str(Vmag))
        if Vmag>sens.hitObject['hold']:
            if sens.hitObject['Leaf']==True:
                sens.hitObject['Leaf']=False
            
            
        sens.hitObject.applyForce(own['Strength'],0)


main()



pin item (loosely)


import bge




def main():


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


    if 'store' not in own:
        own['store']=own.worldPosition.copy()
        own['store2']=own.worldOrientation.copy()
    else:
        Store=own['store']
        own.worldPosition=((own.worldPosition*3)+(own['store']))*.25
        own.worldOrientation=((own.worldOrientation*3)+(ow  n['store2']))*.25
        


main()



Attachments

DeadLeavesAndTheDirtyGroundRec.blend (591 KB)