Question: Timing animations

This means you do not relay on the animation, so option A) and B) are sufficient on your situation.

You do not need any Python code to sense a property. A Property sensor is sufficient enough as long as you have a property to sense.

If you use a float property you need to use Interval mode.
If you use an integer property you can use Equals mode.

Thanks guys

@superflip, the reason why it needs to be a sensor is because it has to do something when the frame is whatever it needs to be. If I get the frame in the script, it will only get the starting frame probably so that doesn’t help. I would need a constant loop to check if it’s on the right frame. And the reason why it isn’t parenting is because it’s in first person and there’s a hand empty that is parented to the armature. Also I would still need to check the frame and create a sensor anyway for attacking so that as I said the attack message or whatever it will be will happen not as soon as the player clicks, but only when the sword is extended far enough away based on the frame.

@monster I know I need a sensor but the problem now I guess is how to I get the frame as a property without an infinite check loop?

check this out

it uses python to run a ping pong animation (procedural)

you can use the same method to control a action using the property “Animus” in this case

:smiley:


import bge
from bge import render


def main():


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


    sens = cont.sensors['Ray']
    power = own['Power']
    switch = 1
    if 'Animus' not in own:
        own['Animus']=0
        own['Flip']=False
    else:
        if power==True:
             
            
            if own['Animus'] <= 116 and own['Flip']==False:
                own['Animus']+=4
                if own['Animus']==120:
                    own['Flip']=True
                    switch=0
            if own['Animus'] >= -118 and own['Flip']==True and switch==1:
                own['Animus']-=4
                if own['Animus']==-116:
                    own['Flip']=False
            own.worldOrientation =own.parent.worldOrientation
            own.applyRotation((0,0,own['Animus']*.005),1)
            
        if sens.positive:
            target=own.parent['Target']
            render.drawLine(own.worldPosition,sens.hitPosition,(1,1,1))
            if target=="Empty" or target==sens.hitObject:
                if sens.hitObject['Side']!=own.parent['Side']:
                    own.parent['Target']=sens.hitObject
                    own.parent['TargetName']=sens.hitObject.name
                    if own.parent['DwellTime']<110:
                        own.parent['DwellTime']+=10
            
    


main()



Attachments

Wrectified_sensor_Component.blend (425 KB)

I kind of get it but I’m not sure. It looks super complicated you got a bunch of stuff going on there.

yeah, I mean the animus part.


if own['Animus'] > 0 and own['Animus'] <=119:
    own['Animus']+=1


if you are running this, it will produce

1 2 3 4 5 6 7…120

if [‘Animus’]!=0--------python
___________---------and------------Action (property) Animus

this way, setting Animus to 1 triggers the animation :smiley:

Fresh example

Just noticed = Delete

main() at the end of script :yes:

Attachments

Anim.blend (401 KB)

Have you seen this?


Thanks again guys

@monster yes I know about frame properties however the only thing is I’m using playAction() which I need so I can alter animation length, unless you can do that with action actuators but I don’t think so.

Yeah,

actu.frame_end = end frame

python--------Action

as sayd you can change the range, surely changeable is :
act.frameStart = 51
act.frameEnd = 100
…and also…
act.frame = 23

anyway be aware, if you use the actuator, then you get one dependence from “cont-roller” very annoyng .
ie , the only way to stop and play the action is using cont.activate() …
the annoyng stuff is that “cont” must be the “real” cont (not one reference) , that must be attached to the actuator …
seem little stuff but can be very annoyng.

anyway to me not seem that solve the problem.

if you use one actuator to run different actions , how you make to know what is the current action? (you cannot make reference to the actuator)

so you need i guess to write the current action in one string property …
and voila , probably that was the piece that lacks…

one time you know it you should know also the layer where it run.(layer of the action)
the animations run time based , ie: a “attack” action take the same time in a PC slow or fast…more or less…

if you have the framerate animation setted at 24.0 (as default) ,the frame increase is of 0.4 if the FPS is 60.0(PC FAST)
and 0.8frameanimation at 30.0FPS (PC slow)

using round(frame) (or int(frame))

not fail until 30 FPS and also a bit less, if is more slow can fail (but probably the game is not more much funny :D)



if own["action"] == "attack": 
    frame = round(own.getActionFrame(layer_numb)) #
    if own["old_frame_action"] != frame:
        own["old_frame_action"] = frame
        #launch a string-command now
        own["fire"] = True
    else:
        own["fire"] = False
else:
    own["fire"] = False


3 property required

then …if “fire” … addobject…

redundant ? a lot , but … maybe using messages rather than the property fire avoid a bit of “overhead” , a a sort of command
problem is that message “spawn random” at all objects :confused:

PS: nevermind :smiley: …internal message…

comand: str

if comand not equal [] -> and -> command assign = “”

so, rather than -> own[“fire”] = True # to clean each time …
own[“comand”] = “fire” # “auto cleaned”

clear, only one command can be executed … better, more simple than manage one list :wink:

I’m not really sure what this would do. I can’t just cut the animation short BPR I have to actually change the length of the whole thing which can be done using the playAction() command. Here is an example from my game:

rightArm.playAction(“rightArm”, 135, 170, 0, 0, 0, 0, 0.0, 0, 0.75*rightArm[‘swingspeed’])

All those 0’s are parameters that do who knows what but the last one, “0.75*rightArm[‘swingspeed’]” changes the speed.

changing the value added to the property each frame = playspeed

here is an example demonstrating using a action with the prop

edit: AnimSpeed = demonstrating changing play speed

Attachments

Anim2.blend (403 KB)AnimSpeed.blend (404 KB)

and finally I give you what you seek :smiley:

space = play action

shift = double action speed

Attachments

AnimSpeedPlayAction.blend (403 KB)

Ok I see what you’re doing! The thing is now my playAction()s are within a bigger script. So I don’t know if it will keep on looping or just do one increment and stop immediately. Here’s an example:



if rmb.positive:
    #Check if lh is shield
    #If not, animate, start block timer.
    if itemRh['section'] == "Weapons":
        if itemRh['equip'] == 2:
            if (90 < rightArm.getActionFrame(0) < 135) == False and (135 < rightArm.getActionFrame(0) < 170) == False and (170 < rightArm.getActionFrame(0) < 200) == False and (200 < rightArm.getActionFrame(0) < 230) == False:
                if mmb:
                    rightArm.playAction("rightArm", 230, 240, 0, 0, 0, 0, 0.0, 0, 0.5)
                    handR.playAction("playerRightHandAction", 230, 240, 0, 0, 0, 0, 0.0, 0, 0.5)
                    rightArm['altBlockB'] = True
                    player['altBlockTimer'] = 0.0
                else:
                    rightArm.playAction("rightArm", 250, 260, 0, 0, 0, 0, 0.0, 0, 0.5)
                    handR.playAction("playerRightHandAction", 250, 260, 0, 0, 0, 0, 0.0, 0, 0.5)
                    rightArm['blockB'] = True
                    player['blockTimer'] = 0.0  

And it also goes on to do other things and check other things.




if own['Anim']=endFrame:
    own['Anim']=0
    if loop == True:
        own['Anim']=1
        



:smiley:

I would have your weapons manager, also manage each action, that is dependent on the weapon system.

and have a seperate ‘Motion’ system that also plays animations

Eheh question, how does if loop == true: make it loop?

Yeah, you would need to define it somewhere,

like own[‘Loop’] or?

as if Anim!=0-------play script

will take it from there

if you set Anim to 1, it starts the animation over again,

so 1 -> end frame -> back to 1 -> end frame

loopings :smiley: