good animation logic setup?

does anyone have a fully functioning animation logic setup?

example walk animations:
i set up the keyboard sensors with true level triggering to the animation actuators, which have loop stop etc as always
but now in certain moments when i push multiple keys at the same time or other keys which are not set up by sensors the animation freezes
applied layers, worked better, at some point freezes too

in my earlier projects i came on quicklier and something like animations didnt take this long

please i need some advice or maybe an idea for a working animation logic setup or an example file or something.

i suggest to use a string as “intermediary”, rather than set directly the action

for example:
[add a property named “action” -> string]

string manipulation

if keyboard W: -> and -> “action” = “walk”
if keyboard SPACE: -> and -> “action” = “jump”

then you do a set of bricks that read the property “action”

string excecution (action)

if property “action” equal “walk” -> and -> action “walk”(brick action called “walk”)
if property “action” equal “jump” -> and -> action “jump”(brick action called “jump”)

so, you can also see (with debug property) what is the current action that run

Edit:

added a “gamelogic simple” based solution

this is nice, because you don’t need to worry about animations stepping on each other,

you can play two actions at one time, by adding another actuator, and triggering it with the same style scripts,

Attachments

threeAnimationSwitch.blend (408 KB)

@MarcoIT: yeah i already tried with properties and scripting too, sorry didnt mention it ^^

@blueprintRandom: thx the script looks promising i didnt put into thought what would happen when the “W”-Button is NOT clicked" :smiley:

@MarcoIT: yeah i already tried with properties and scripting too, sorry didnt mention it ^^

and it not work? (should)

maybe some mistakes with UpperCase lowercase, something as “Jump” rather than “jump” or vice versa…

not good
3 scripts to manage(bad, since require that each action has the same range)
3 actions (plus a lot of dependences avoidable… each time you write the name of action)
:eyebrowlift2:

Yeah that was just showing how to do it quick and dirty,

A real manager would be all one script,

Like

If jumpclock ==0 and Keypress w.positive:
Play walk

If jumpclock !=0 and own.localLinearVelocity.y>2.5:
Play forward jump

Etc and then at the end it would feed the actuator

and you are sure that it works with walking animations?

i have animations for:

walking forward
backward
left right
and diagonally forward and left
diagonally forward right
diagonally backward left
diagonally backward right

the problem occurs while walking diagonally

i assigned the properties per python script and it kinda worked
but under real gaming conditions the buttons would be hit very fast and agitadely
and i also tried to hit them fast and then the property got mixed up
at some point the character was walking diagonally forward left but the property said “idle”

im also thinking about giving a delay to the animations but am not sure if thats even useful

ps: im using blender 2.72



import bge

cont = bge.logic.getCurrentController()

own = cont.owner

Up = cont.sensors['Up']
Right = cont.sensors['Right']
Down = cont.sensors['Down']
Left = cont.sensors['Left']
Ray = cont.sensors['NegZRay']

Space = cont.sensors['Space']

sensorList = [Up,Right,Down,Left,Space]
move =[]
for sens in sensorList:
    if sens.positive:
       move += [sens.name]

    if own['JumpClock']==0 and Ray.positive:
   
    if move ==['Up','Space']:
       Do forward Jump
       own['JumpClock']=30

    if move ==['Space']:
       Do Jump
       own['JumpClock']=30
       
    if move ==['Down'] : 
       Do down stuff like set action, and apply forces etc
    if move ==['Right','Down']
       do down right stuff
    if move ==['Up']:
       do up stuff
    if move == ['Up','Right']
       do up right stuff



actu = cont.actuators['Action']
actu.action = (action you set with logic)
cont.activate(actu)

etc.

you can add in nice little things like, are you pushing on a block?

are you against a wall?

Demo tonight

this will help my own project avoid logic brick hell as well,

thanks for the code :smiley:
what do i have to put into the move array?

I am scripting a dynamic motion controller, that will also happen to play animations ,

It will probably be about 50 minutes before I can sit down back in front of my pc for more then 30 seconds at a time ,

i appreciate any kind of help doesnt matter how long it takes :slight_smile:
i am very thankful

Ok, movement and readout is done,

check out the property ‘type’ in the object,

1 = First person mouse controlled rotation

0 = third person

next is a method that plays the animations, or even mixes them (this could be trickier though)

Attachments

ControlRigDelta.blend (416 KB)

Ok, here is a rig, with a actor and some of the animation sheet filled,

Attachments

ControlRigDeltaBravo.blend (525 KB)

:eek: ops.
i tried now with 2 animation and not work :eek:
more precisely ,

start…with idle (OK)
W -> walk -> OK
release W -> idle -> BLOCKED (still on a frame of walk)
press W -> walk -> OK
release W -> idle -> BLOCKED (still on a frame of walk)

tried also changing “no W” to a “SPACE” but same result.

i was sure that was a easy task for bricks :confused:

so, better use playAction() (but using bricks as reference :D)

PS:i use 2.69

ok, written now


#animationgrabber.py

class Animation:
    def __init__(self, gob, name, fs, fe, ly, pr, bi, pm, lw):
        self.gob = gob
        self.name = name
        self.fs = fs
        self.fe = fe 
        self.ly = ly
        self.pr = pr 
        self.bi = bi 
        self.pm = pm 
        self.lw = lw
        self.sp = 1.0
        
    def play(self):
        self.gob.playAction(self.name, self.fs, self.fe, layer=self.ly, priority=self.pr, blendin=self.bi, play_mode=self.pm, layer_weight=self.lw, speed=self.sp)
    
    def stop(self):
        self.gob.stopAction(self.layer)
    
    def is_running(self):
        return self.gob.isPlayingAction(self.ly)
    
    @property
    def frame(self):
        return self.gob.getActionFrame(self.ly)
    
    @frame.setter
    def frame(self, fr):
        self.gob.setActionFrame(fr, self.ly)
        
        
def grab_all_actions(gob):
    actions = {}
    for a in [ a for a in gob.actuators if hasattr(a, "action") and a.action]:
        name, fs, fe, ly, pr, bi, pm, lw = a.action, a.frameStart,a.frameEnd,a.layer,a.priority,a.blendIn,{False:0,True:1}[bool(a.mode)], a.layerWeight
        actions[a.name] = Animation(gob, name, fs, fe, ly, pr, bi, pm, lw)
    return actions



how work?
put this code in a module (animationgrabber.py)
then from a normal module(or script) write:


own = cont.owner
if not "animations" in own:
    own["animations"] = animationgrabber.grab_all_actions(own)
    own["animations"]["idle"].play()


PS:
note that the name of the actions is the name of the “brick action” (not necessarly the name of the action)
so in this case must be a brick action named “idle”
PS2:
it support only play_mode <play>, and <loop> (if is not play, is automatically “loop_stop”) (no pingpong,not flipper)

PS3:
also , this code is basically a copy and paste of a code of another user , is not my stuff.
but not remember the name , something as “LinX” from Canada

I have a working version using an animation property, and deactivating all bricks except the applicable ones, Its in contolRigEpsilon I’ll upload it in a bit when I get a chance,

Attachments

ControlRigEpsilon.blend (647 KB)

i cannot see these superspaghetti.
i take some minute to understand how the cube do the activation of the action(of armature) :smiley:

why?
let me , the parent (box) has already too many task to do.

will be not better write just the action (on the box itself)
then the armature has just to read it ?

also to keep in count that the children found quikly the parent, is the inverse that is more complex.

the armature will have just to do:
what action i have to run?

statusbox = own.parent[“status”]
if statusbox == “” : cont.activate(etc)

or also much better, (if is possible, sound as a good idea) as you had done:


for act in cont.actuators:
    if act.name == statusbox:
        cont.activate(act)

but from the armature obj ,this way the box has less problems to solve :wink: