WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   avatar walkto interrupt (https://forum.worldviz.com/showthread.php?t=4517)

Meneer_Aart 03-14-2013 12:28 AM

avatar walkto interrupt
 
Hello,

This maybeIs there a way to stop an avatar that's walking from point A to point B "dead in it's tracks"?

My code untill now looks somewhat like this:

Code:

def walk1():
        yield viztask.waitKeyDown( ' ' )
        yield viztask.addAction(avatar, vizact.walkTo([pointA]))
        yield viztask.addAction(avatar, vizact.walkTo([pointB]))
        yield viztask.addAction(avatar, vizact.walkTo([pointC]))
              avatar.state(14)
        yield viztask.waitTime(10)
        viztask.schedule(walk2())

def walk2():
        yield viztask.waitKeyDown( ' ' )
        yield viztask.addAction(avatar, vizact.walkTo([pointD]))
        yield viztask.addAction(avatar, vizact.walkTo([pointE]))
              avatar.state(14)
        yield viztask.waitTime(10)
#main
viztask.schedule(walk1())

So during ANY of the walkto actions i want to be able to stop the avatar where he is, and let him perform some kind of action on that spot.

Jeff 03-14-2013 06:04 AM

In the following example the spacebar is used to start and stop the avatar as he walks between two points:
Code:

import viz
import viztask
import vizact
viz.go()

viz.add('ground.osgb')
avatar = viz.addAvatar('vcc_male2.cfg',pos=[0,0,9])
avatar.state(1)

walkLeft = vizact.walkTo([2.5,0,9])
walkRight = vizact.walkTo([-2.5,0,9])
walkActions = viz.cycle([walkLeft,walkRight])

waitSpaceBar = viztask.waitKeyDown(' ')
waitLeft = viztask.waitActionEnd(avatar,walkLeft)
waitRight = viztask.waitActionEnd(avatar,walkRight)
waitActions = viz.cycle([waitLeft,waitRight])

def walkAndStopTask():
        yield waitSpaceBar
        while True:
                condition = waitSpaceBar
                walkAction = walkActions.next()
                waitAction = waitActions.next()
                while condition == waitSpaceBar:
                        avatar.runAction(walkAction)
                        d = yield viztask.waitAny([waitSpaceBar,waitAction])
                        condition = d.condition
                        if condition == waitSpaceBar:
                                avatar.clearActions()
                                yield waitSpaceBar
                       
viztask.schedule(walkAndStopTask())


Meneer_Aart 03-20-2013 01:41 AM

Thanks for your reply Jeff. I've tried the "clearactions()" statement.
However, since i'm using schedule to arrange the actions, i have to kill that as well to prevent the other walking actions from running.

I've tried this:

Code:

def walk1():
        yield viztask.waitKeyDown( ' ' )
        yield viztask.addAction(avatar, vizact.walkTo([pointA]))
        yield viztask.addAction(avatar, vizact.walkTo([pointB]))
        yield viztask.addAction(avatar, vizact.walkTo([pointC]))
              avatar.state(14)
        yield viztask.waitTime(10)
        viztask.schedule(walk2())

def walk2():
        yield viztask.waitKeyDown( ' ' )
        yield viztask.addAction(avatar, vizact.walkTo([pointD]))
        yield viztask.addAction(avatar, vizact.walkTo([pointE]))
              avatar.state(14)
        yield viztask.waitTime(10)

def stop():
        avatar.clearactions(0)

#main
t = viztask.schedule(walk1())

vizact.onkeydown('l',t.kill)
vizact.onkeydown('k',stop)

And this works, it stops the avatar completely and he returns to his idle state. However, it is inconvenient to have to push 2 keys to stop the avatar, so i tried to add the killing of the schedule to my stop command:

Code:

def stop():
              t.kill
        avatar.clearactions(0)

vizact.onkeydown('k',stop)

But this doesn't work for me, Is there a way to combine the 2 commands? I feel i'm overlooking something very simple here, but i can't quite put my finger on it.

Jeff 03-20-2013 01:59 AM

Once the user stops the avatar, what is the next action that should be applied to the avatar? If the avatar stops on the way to PointA, should he pick up from the same place later and continue to PointA, or go to PointB, or should the whole task be ended?

Meneer_Aart 04-02-2013 06:45 AM

Jeff, i'm writing some software for a military simulation, the avatar actually gets shot and killed.
So the whole task should be ended, i would like the avatar to assume a specific state (lie down) and perform no actions anymore after that.

Meneer_Aart 04-09-2013 05:39 AM

Not to sound too desperate, but i'm still having some difficulties with this. Does anybody perhaps have a suggestion for me?

Jeff 04-09-2013 02:41 PM

If you're waiting for either the walk action to finish or the keypress to occur you should use the viztask.waitAny command. Then if the event was a keypress you can leave the task using the return command:
Code:

d = yield viztask.waitAny([waitSpaceBar,waitAction])
condition = d.condition
if condition == waitSpaceBar:
        avatar.clearActions()
        return



All times are GMT -7. The time now is 01:33 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC