Idle State in BGE with Python

I’ve been having problems with idle animations interfering with other animations. The problem is that my idle animation prevents other animations from playing or it interferes with them. I’ve tried using logic bricks and python but concluded with the corresponding results.

How can I make a perfect idle state in my game?

I’ve also been considering using the “all keys” method where if no keys are being registered, the idle animations play. Another method I’ve been considering would be the “no movement detected” method, which is when the player’s position is remaining constant, the idle animations play.

if movment detected or keys pressed - set prop resetTime to value

over time reduce prop resetTime

if time zero play idle / use idle state

else active state

prop sensor
movement sensor
python controllers or logic states

How would I detect movement with Python?

I already have a timer property intended for something else, but I could just recycle it.

Also, how do you add the “all keys” in python (if I have to revert to that)?

I proccess input with one object and target any game object with it personally

anytime I detect input (keyboard sensors and joystick sensors etc) it gathers a string and checks against a dictionary, and then sends game commands to the agent, when it does this it also sets the reset timer.

agent[‘Move’] = [indexedGatheredInputs]
agent[‘ResetTime’] = 60

this way each agent has a min amount of sensors
also upbge has movement sensor logic brick

so agent only has

[prop not zero]------[python and prop -1]
movement–and------set resetTimer = 60
prop = 0 —and----idle stuff

Alright, I see what you’re going for.

I was considering another option whereas the idle animation would play when no other animations are playing. Since the player can perform other actions…

yeah I use a actstrip

if not 'ActStrip' in own:
    process input
    currentState = actStrip[0]
    currentFunction = own['stateDictionary'][ currentState[0]]

where a actstrip is like

actstrip = [ [‘Navigate’, [dataForNavigate]], [‘Punch’,[dataForPunch]] ]

so somewhere above I do

def Navigate(data):

and finally I create the dictionary

dict = { ‘nameOfState’:stateFunction }
creating a hashtable of states

Um, before I proceed…

What’s ActStrip?

it’s a system to use python to create an infinite number of discrete states.

you can stack em like

walk here, flip switch, dialog

agent[‘ActStrip’] =[ [‘Navigate’,[mark, navmesh]] , [‘switch’,[target,frame]],[‘dialog’,[string]] ]

as a state is finished it’s popped, triggering the next state

states can also proccess input and call other functions*

Alright then, this seems confusing?

Is there a simpler alternative? Sorry for asking, I’ve been using Python for less a year now…

yeah I just did it this way so players, enemies, acting etc is all the same system

inside each function I animate , cast rays etc
(like swing sword or push crate etc)

it just isolates each state to a python snippet and you can perpetually add more states without rewritting anything.

you could just use a states and a bitmask

own.state = bitmask

to change states and use python or logic bricks defined in those states

(but you have only 16 possible states)

sometimes frontloading complexity removes it from everywhere else*

all of it makes much better sense when you tried every other approach until they burst into flames.

again my method

1.(gather input in controller object)
2. set input in agent and set reset Timer
3. agent either acts on input or is already acting

when a agent is pushed, it’s movement sensor kicks him into action so people don’t ever slide aground(it looks funky)

(people tend to try and face the velocity and walk)

this is what manic mack uses

Oh, okay then. So I’m assuming the “agent” is the owner or player. Then
“[[’‘Navigate’,[mark, navmesh]], [‘switch’, [target,frame]], [‘dialog’,[string]] ]” is probably the switch
being activated. Then the “dialog” segment is he dailog being activated.

So that’s basically a way of adding states?

a list of states if need be

(multiple goals to achieve in order)

this is a old demo of a older version of the system

So those are properties in the “[]”?

I might consider another method, sorry…


once you get to keymapping and state machines revist.

also it make more sense when you are staring at a working .blend :smiley:

you can just use a value for each state in logic and if they are all zero play idle.

or something along those lines.

So then how do you suppose I do it then?