Walk to mark, focus on target example

Updated file and video

Attachments

ActStrip4.blend (811 KB)

Version 2 = ActStrip

import bge

import copy
def main():


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


    Collision = cont.sensors['Collision']
    X = cont.sensors['KeyX']
    
    if 'actStrip' not in own:
        if Collision.positive and X.positive:
            own['actStrip']=copy.deepcopy(Collision.hitObject['ActStrip'])
            
            own['Active']=True
    
    else: 
           
        own['Read']=str(own['actStrip'])
        if len(own['actStrip'])>=1:
            Next = own['actStrip'][0]
            
            
            
            #Run to mark
            if Next[0]=='Mark2':
                Mark=own.scene.objects[Next[1]]
                Vect2 = own.getVectTo(Mark)
                if len(Next)<3:
                    
                    
                    Next.append(int(Vect2[0]*(100-own['MoveRateRun'])))
                else:
                    Time = Next[2]
                    if Time>=1:
                        own.alignAxisToVect(Vect2[1],1,.1)
                        own.alignAxisToVect([0,0,1],2,1)
                        own.applyMovement(Vect2[1]*(Vect2[0]/Time),0)
                        Next[2]-=1   
                    if Time==0:
                        own.worldPosition=Mark.worldPosition
                        Diff = own.worldOrientation.col[1]-Mark.worldOrientation.col[1]
                        own['Read2']=Diff.magnitude
                        if Diff.magnitude>.05:
                            own.alignAxisToVect(Mark.worldOrientation.col[1],1,.1)
                            own.alignAxisToVect([0,0,1],2,1)
                            
                        else:
                            own.worldOrientation=Mark.worldOrientation
                            own['actStrip'].pop(0)
            #walk to mark                
            if Next[0]=='Mark1':
                Mark=own.scene.objects[Next[1]]
                Vect2 = own.getVectTo(Mark)
                if len(Next)<3:
                    
                    
                    Next.append(int(Vect2[0]*(100-own['MoveRateWalk'])))
                else:
                    Time = Next[2]
                    if Time>=1:
                        own.alignAxisToVect(Vect2[1],1,.1)
                        own.alignAxisToVect([0,0,1],2,1)
                        own.applyMovement(Vect2[1]*(Vect2[0]/Time),0)
                        Next[2]-=1   
                    if Time==0:
                        own.worldPosition=Mark.worldPosition
                        Diff = own.worldOrientation.col[1]-Mark.worldOrientation.col[1]
                        own['Read2']=Diff.magnitude
                        if Diff.magnitude>.05:
                            own.alignAxisToVect(Mark.worldOrientation.col[1],1,.1)
                            own.alignAxisToVect([0,0,1],2,1)
                            
                        else:
                            own.worldOrientation=Mark.worldOrientation
                            own['actStrip'].pop(0)
            
            #Act                    
            elif Next[0]=="Act":
                Time = Next[2]
                if Time<Next[3]:
                    #print('Playing')
                    own.playAction(Next[1],Time,Time,layer=1, priority=0, blendin=0, play_mode=0, layer_weight=0.0, ipo_flags=0, speed=1.0, blend_mode=0)                 
                    Next[2]+=1
                else:
                    own.stopAction(1)
                    own['actStrip'].pop(0)    
        
        else:
            print('RemActStip')
            del own['actStrip']
            own['Active']=False            
                    
main()



Attachments

ActStrip.blend (656 KB)

Attachments

ActStrip2.blend (694 KB)

Suggestions as to how to make the system easier to use/more flexible would be nice :smiley:

I think it works fine, the scripts short too…but you dont really get module mode/functions yet do you? Reason I ask is because is because you have

#act
#walktomark
etc

could be seperate functions only run when needed

does this use less resources then elif?

I thought a single branch decision was just as fast?

you still need to look up the module kinda right?(when its called*)

I understand modules, and can use them, but I thought the advantage was only applicable when you call just 1 piece of a script using module mode?

edit:

dictionary calling a function is the way to go apparently

you can still use one long module…with different functions inside…module mode can allow you to call specific functions(chucks of code) from an sensor. Store it. and use it in another part of the script. Say when you call another functions with a different sensor. Plus you dont have alot of your constant variables at Module level. So they’re are always being computated as long as the script in running. in Module mode anything all the way indented to the left, only assigns once, the first time the module is called

Ok, I just looked at it,

def act(Action,Time,EndFrame):

so Next = own[‘actStrip’][0]
if Time is a passed reference to a list value (Next[2])

like act(Next[1],Next[2],Next[3])

and in the function Time-=1 will it effect the list own[‘actStrip’][0][2] ?

edit should I use return somehow instead?

edit:
got it working using eval()

import bge

import copy
def set(cont,Next):
    own=cont.owner
    target = own.scene.objects[Next[1]]
    prop = Next[2]
    target[prop]=Next[3]
    own['actStrip'].pop(0)


def toggle(cont,Next):
    own=cont.owner
    target = own.scene.objects[Next[1]]
    prop = Next[2]
    if target[prop]==False:
        target[prop]=True
    else:
        target[prop]=False
    own['actStrip'].pop(0)
    
    
def act(cont,Next):
    own=cont.owner
    Time = Next[2]
    if Time<Next[3]:
                    #print('Playing')
        own.parent['GFX'].playAction(Next[1],Next[2],Next[2],layer=6, priority=1, blendin=0, play_mode=1, layer_weight=0.0, ipo_flags=0, speed=0.0, blend_mode=1)                 
        Next[2]+=1
    else:
        own.parent['GFX'].stopAction(1)
        own['actStrip'].pop(0)    
           
           
           
def walk(cont,Next):
    own = cont.owner
    Mark=own.scene.objects[Next[1]]
    Vect2 = own.parent.getVectTo(Mark)
    if len(Next)<3:
        
        
        Next.append(int(Vect2[0]*(100-own.parent['MoveRateWalk'])))
    else:
        Time = Next[2]
        if Time>=1:
            own.parent.alignAxisToVect(Vect2[1],1,.1)
            own.parent.alignAxisToVect([0,0,1],2,1)
            own.parent.applyMovement(Vect2[1]*(Vect2[0]/Time),0)
            Next[2]-=1   
        if Time==0:
            own.parent.worldPosition=Mark.worldPosition
            Diff = own.parent.worldOrientation.col[1]-Mark.worldOrientation.col[1]
            own['Read2']=Diff.magnitude
            if Diff.magnitude>.05:
                own.parent.alignAxisToVect(Mark.worldOrientation.col[1],1,.1)
                own.parent.alignAxisToVect([0,0,1],2,1)
                
            else:
                own.parent.worldOrientation=Mark.worldOrientation
                own['actStrip'].pop(0)
            
            
            
def run(cont,Next):
    own=cont.owner
    Mark=own.scene.objects[Next[1]]
    Vect2 = own.parent.getVectTo(Mark)
    if len(Next)<3:
        
        
        Next.append(int(Vect2[0]*(100-own.parent['MoveRateRun'])))
    else:
        Time = Next[2]
        if Time>=1:
            own.parent.alignAxisToVect(Vect2[1],1,.1)
            own.parent.alignAxisToVect([0,0,1],2,1)
            own.parent.applyMovement(Vect2[1]*(Vect2[0]/Time),0)
            Next[2]-=1   
        if Time==0:
            own.parent.worldPosition=Mark.worldPosition
            Diff = own.worldOrientation.col[1]-Mark.worldOrientation.col[1]
            own['Read2']=Diff.magnitude
            if Diff.magnitude>.05:
                own.parent.alignAxisToVect(Mark.worldOrientation.col[1],1,.1)
                own.parent.alignAxisToVect([0,0,1],2,1)
                
            else:
                own.parent.worldOrientation=Mark.worldOrientation
                own['actStrip'].pop(0)












#______________________________________________________________________#
########################################################################


def main():
    cont = bge.logic.getCurrentController()
    own = cont.owner


    
    if 'GFX' not in own.parent:
        for child in own.parent.children:
            if 'Armature' in child:
                own.parent['GFX']=child
                print('FoundGFX')
    Collision = cont.sensors['Collision']
    X = cont.sensors['KeyX']
    
    if 'actStrip' not in own:
        if Collision.positive and X.positive:
            own['actStrip']=copy.deepcopy(Collision.hitObject['ActStrip'])
            
            own['Active']=True
    
    else: 
           
        own['Read']=str(own['actStrip'])
        if len(own['actStrip'])>=1:
            Next = own['actStrip'][0]
            func = eval(Next[0])
            func(cont,Next)
            
            
            
           
        
        else:
            print('RemActStip')
            del own['actStrip']
            own['Active']=False            
                    
main()



ok got it!

now it uses a dictionary, and no evil eval()

import bge

import copy
def set(cont,Next):
    own=cont.owner
    target = own.scene.objects[Next[1]]
    prop = Next[2]
    target[prop]=Next[3]
    own['actStrip'].pop(0)


def toggle(cont,Next):
    own=cont.owner
    target = own.scene.objects[Next[1]]
    prop = Next[2]
    if target[prop]==False:
        target[prop]=True
    else:
        target[prop]=False
    own['actStrip'].pop(0)
    
    
def act(cont,Next):
    own=cont.owner
    Time = Next[2]
    if Time<Next[3]:
                    #print('Playing')
        own.parent['GFX'].playAction(Next[1],Next[2],Next[2],layer=6, priority=1, blendin=0, play_mode=1, layer_weight=0.0, ipo_flags=0, speed=0.0, blend_mode=1)                 
        Next[2]+=1
    else:
        own.parent['GFX'].stopAction(1)
        own['actStrip'].pop(0)    
           
           
           
def walk(cont,Next):
    own = cont.owner
    Mark=own.scene.objects[Next[1]]
    Vect2 = own.parent.getVectTo(Mark)
    if len(Next)<3:
        
        
        Next.append(int(Vect2[0]*(100-own.parent['MoveRateWalk'])))
    else:
        Time = Next[2]
        if Time>=1:
            own.parent.alignAxisToVect(Vect2[1],1,.1)
            own.parent.alignAxisToVect([0,0,1],2,1)
            own.parent.applyMovement(Vect2[1]*(Vect2[0]/Time),0)
            Next[2]-=1   
        if Time==0:
            own.parent.worldPosition=Mark.worldPosition
            Diff = own.parent.worldOrientation.col[1]-Mark.worldOrientation.col[1]
            own['Read2']=Diff.magnitude
            if Diff.magnitude>.05:
                own.parent.alignAxisToVect(Mark.worldOrientation.col[1],1,.1)
                own.parent.alignAxisToVect([0,0,1],2,1)
                
            else:
                own.parent.worldOrientation=Mark.worldOrientation
                own['actStrip'].pop(0)
            
            
            
def run(cont,Next):
    own=cont.owner
    Mark=own.scene.objects[Next[1]]
    Vect2 = own.parent.getVectTo(Mark)
    if len(Next)<3:
        
        
        Next.append(int(Vect2[0]*(100-own.parent['MoveRateRun'])))
    else:
        Time = Next[2]
        if Time>=1:
            own.parent.alignAxisToVect(Vect2[1],1,.1)
            own.parent.alignAxisToVect([0,0,1],2,1)
            own.parent.applyMovement(Vect2[1]*(Vect2[0]/Time),0)
            Next[2]-=1   
        if Time==0:
            own.parent.worldPosition=Mark.worldPosition
            Diff = own.worldOrientation.col[1]-Mark.worldOrientation.col[1]
            own['Read2']=Diff.magnitude
            if Diff.magnitude>.05:
                own.parent.alignAxisToVect(Mark.worldOrientation.col[1],1,.1)
                own.parent.alignAxisToVect([0,0,1],2,1)
                
            else:
                own.parent.worldOrientation=Mark.worldOrientation
                own['actStrip'].pop(0)








MyDict = { 'run':run, 'walk':walk , 'act':act, 'toggle':toggle , 'set':set } 


#______________________________________________________________________#
########################################################################


def main():
    cont = bge.logic.getCurrentController()
    own = cont.owner


    
    if 'GFX' not in own.parent:
        for child in own.parent.children:
            if 'Armature' in child:
                own.parent['GFX']=child
                print('FoundGFX')
    Collision = cont.sensors['Collision']
    X = cont.sensors['KeyX']
    
    if 'actStrip' not in own:
        if Collision.positive and X.positive:
            own['actStrip']=copy.deepcopy(Collision.hitObject['ActStrip'])
            
            own['Active']=True
    
    else: 
           
        own['Read']=str(own['actStrip'])
        if len(own['actStrip'])>=1:
            Next = own['actStrip'][0]
            
            MyDict[Next[0]](cont,Next)
            
            
            
           
        
        else:
            print('RemActStip')
            del own['actStrip']
            own['Active']=False            
                    
main()



Next, how to make a dialog play system, that is generic enough for any game?

Attachments

ActStrip3.blend (662 KB)

Begin Blender Arms Race

Attachments

ActStrip4.blend (811 KB)

Bump = updated First Post

You program your allies to do stuff in videogames with this?Is that what it does?

many many possibilities :slight_smile:

you can use it to control in game cut scenes,

you can use it for a tactical rpg

you can use it to line up to ladders, doors and switches, and play the animations and enter the proper states, and toggle properties…

its pretty handy I think at least,

and yes, you could use keypress + a ray hitpoint to give a order to a friendly for sure.

you can even say ‘hold’ give a list of orders and then say ‘go’

if you setup your main() that way.

I am only interrested in making many allies follow the orders i give them.But each in a certain amount of time.

I have another idea.But it is hard.
Maybe this could be used to allow enemies to learn the fighting tactics of the allies.

Hello,
thank you for the file, very nice and quite useful!
Bye

Thank you OTO!

Any requests for functions people?

I am thinking that navigate should play a walk cycle in the player, defined by a property, walkType - in each player
(also walk and run)


def openClose(cont,Next):
    own=cont.owner
    target = own.scene.objects[Next[4]]
    Bool = target[Next[5]]
    Max = target['OpenClose']
    Time = Next[2]
    if 'OpenClose' not in own:
        if Bool==True:
            own['OpenClose']=False
            
        else:
            own['OpenClose']=True
            Next[2]=Next[3]
    else:
        
        if own['OpenClose']==False:
            if Next[2]==0:
                Bool=True
            if Time<Next[3]:
                own.parent['GFX'].playAction(Next[1],Next[2],Next[2],layer=6, priority=1, blendin=0, play_mode=1, layer_weight=0.0, ipo_flags=0, speed=0.0, blend_mode=1)
                Next[2]+=1
            else:
                own.parent['GFX'].stopAction(1)
                target.stopAction(1)
                own['actStrip'].pop(0)    
                del own['OpenClose']    
            print(str(Next[2])+' '+str(Max))   
            if Next[2]<=Max:
                target.playAction(target['Animation'],Next[2],Next[2],layer=6, priority=1, blendin=0, play_mode=1, layer_weight=0.0, ipo_flags=0, speed=0.0, blend_mode=1)
                print('PlayingFrame '+str(Next[2]))
                
                    
            else:
                target.playAction(target['Animation'],Max,Max,layer=6, priority=1, blendin=0, play_mode=1, layer_weight=0.0, ipo_flags=0, speed=0.0, blend_mode=1)
                         
            
                
                
        else:
            Bool=False
            if Next[2]>=1:
                own.parent['GFX'].playAction(Next[1],Next[2],Next[2],layer=6, priority=1, blendin=0, play_mode=1, layer_weight=0.0, ipo_flags=0, speed=0.0, blend_mode=1)
                Next[2]-=1
                
            else:
                own.parent['GFX'].stopAction(1)
                own['actStrip'].pop(0)    
                del own['OpenClose']        
            if Next[2]<=Max:
                target.playAction(target['Animation'],Next[2],Next[2],layer=6, priority=1, blendin=0, play_mode=1, layer_weight=0.0, ipo_flags=0, speed=0.0, blend_mode=1)
                print('PlayingFrame '+str(Next[2]))
                
                    
            else:
                target.playAction(target['Animation'],Max,Max,layer=6, priority=1, blendin=0, play_mode=1, layer_weight=0.0, ipo_flags=0, speed=0.0, blend_mode=1)    
                            
                            
                            



Attachments

ActStripBeta.blend (893 KB)

Make recorded action on a npc be triggered by another npc presence.

one, or always?

if once I would use a collider in the room to trigger the event, by appending the correct action strip on the second npc when the first collides with it, then deleting the collider.

if you mean an second npc has vision, you could use a ray or radar sensor or collision, to have the actor append navigate to his own actions strip, if its not already on the strip*