Animation and Sound

I use the cont.activate() method to play sounds and animations. It doesn’t really work though. The animation won’t stop playing and the sound can’t go faster than the .wav’s length. What is a good way to do those two things and have them work correctly?

And while I am at it, how would I make this (code below) do diagonal movement. I was hoping there is a way other than creating 4 more ifs for each key combo.

    if onGround.positive:
        if wKey:
            player.setLinearVelocity((0, speed, 0), True)
            cont.activate(animation)
        elif sKey:
            player.setLinearVelocity((0, -speed, 0), True)
            cont.activate(animation)
        if dKey:
            player.setLinearVelocity((speed, 0, 0), True)
            cont.activate(animation)
        elif aKey:
            player.setLinearVelocity((-speed, 0, 0), True) 
            cont.activate(animation)       
           

Thanks

You may need to use cont.deactivate to stop your animations. Not sure about syncing the wav file with your animations.

As for movement:


fwd = cont.sensors["W"]
back = cont.sensors["S"]
slft = cont.sensors["A"]
srght = cont.sensors["D"]
act = cont.actuators["floormove"]
speed = 2

if (fwd.positive or back.positive) and not (slft.positive or srght.positive):
    cont.activate(walk)
            
if (slft.positive or srght.positive) and not (fwd.positive or back.positive):
    print("sideways")
    cont.activate(idle)
        
if (fwd.positive or back.positive) and (slft.positive or srght.positive): #Here is diagonal movement
    cont.activate(walk)


fspeed = speed * (fwd.positive - back.positive) #fspeed, or forward speed, takes the walking/running/crouch speed and multiplies it by W key and S key pressure to equal our forward/backward speed
sspeed = speed * (srght.positive - slft.positive) #sspeed or sidways speed, takes the walking/running/crouch speed and multiplies it by A key and D key pressure to equal our right/left speed

act.linV = [-fspeed, sspeed, jspeed]



i guess , for the sound .

check the current frame(float) , then , if the current frame is > of X : stop sound.


fr = act.frame #if you use the actuator
if fr > 50:
    cont.deactivate(sound)

this method anyway work better with a big action , where start/end loop is already written somewhere.

otherwise : the sensor actuator ? not work?