WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Walking to many directions. (https://forum.worldviz.com/showthread.php?t=1950)

Moh200jo 04-06-2009 04:23 AM

Walking to many directions.
 
Hi every one, my avatar will walk to unknown distances and directions. I tried to rotate her while she is walking but the code does not response. I am still plying with the following code.
HTML Code:

import viz
viz.go()
avatar = viz.add('vcc_female.cfg')
avatar.setPosition(0,0,5)
pos = avatar.getPosition()
ss=1
def myKeyboard(key):
        ss=1
        gg=5
        pos = avatar.getPosition()
        if key == viz.KEY_UP:
                ss=ss+5
                walk_Forward = vizact.walkTo([pos[0], pos[1],pos[2]+ss])
                avatar.addAction(walk_Forward)
        if key==viz.KEY_LEFT:
                gg=gg + 10
                rotate=vizact.spin(0,1,0,gg,1)
                avatar.addAction(rotate)
               
        if key == viz.KEY_DOWN:
                ss=ss+5
                walk_Forward = vizact.walkTo([pos[0], pos[1], pos[2] - ss])
                avatar.addAction(walk_Forward)
       
viz.callback(viz.KEYBOARD_EVENT,myKeyboard)



Any help would be appreciated.
Thanks,

Jeff 04-06-2009 08:33 AM

If you want two actions to occur simultaneously you can add them to different pools. If you don't specify the pool the default is 0 and it will be added to the end of the object's queue or waiting list. This adds rotate to pool 1
Code:

avatar.addAction(rotate, pool = 1)

Moh200jo 04-06-2009 09:10 AM

Oh, thanks Jeff!
But when the avatar stopped for awhile, and then she wants to continue with same direction the code takes her to the other direction (z-axis).
I have tried to increment x-axis but wasn’t practically.
As well as I tried to make the mainview to follow the avatar, when this has been done, the key function does not work probably

HTML Code:

import viz
import viztask
viz.go()
mainview=viz.clearcolor(viz.SKYBLUE)
avatar = viz.add('vcc_female.cfg')
avatar.setPosition(0,0,9)
pos = avatar.getPosition()
#view = viz.MainView
#link = viz.link(avatar, view)
#link.preTrans([0,-.5,-5])
ss=1
def myKeyboard(key):
        ss=1
        gg=5
        global walk_Forward
        pos = avatar.getPosition()
        if key == viz.KEY_UP:
                ss=ss+5
                walk_Forward = vizact.walkTo([pos[0], pos[1],pos[2]+ss])
                avatar.addAction(walk_Forward,pool=1)
        if key==viz.KEY_LEFT:
                gg=gg + 10
                rotate=vizact.spin(0,1,0,gg,1)
                avatar.addAction(rotate, pool = 1)
        if key == viz.KEY_DOWN:
                ss=ss+5
                walk_Forward = vizact.walkTo([pos[0], pos[1], pos[2] - ss])
                avatar.addAction(walk_Forward)
        viz.callback(viz.KEYBOARD_EVENT,myKeyboard)


Jeff 04-06-2009 11:52 AM

If you want to link the avatar to the viewpoint, you could use keyboard navigation like this to move the viewpoint and avatar forward and turn side to side.

Code:

import viz
viz.go()

viz.add('tut_ground.wrl')

avatar = viz.add('vcc_female.cfg')
avatar.state(1)

import viztracker
keyTracker = viztracker.Keyboard6DOF(forward=viz.KEY_UP,backward=viz.KEY_DOWN,turnRight=viz.KEY_RIGHT,turnLeft=viz.KEY_LEFT)

view = viz.MainView
viz.link(keyTracker, view)

link = viz.link(view, avatar)
link.preTrans([0,-1.8,2])

#change the state when avatar stops or starts
pos = avatar.getPosition()
def checkState():
       
        global pos
        if pos == avatar.getPosition():
                avatar.state(1)
        else:
                pos = avatar.getPosition()
                avatar.state(2)
               
vizact.ontimer(.1, checkState)


Moh200jo 04-07-2009 05:44 AM

That is brilliant, but still there is small problem, which is the speed. Once the avatar’s speed has been increased, the user will realize that the mainview is moving not the avatar. So how can I handle this issue?
Please just add this line to your code and then you will see what will happen:
HTML Code:

avatar.speed(5)
Thanks a lot for all your efforts

Jeff 04-07-2009 06:56 PM

This creates a KeyboardCamera object. Use the sensitivity method to scale the movement and turning speeds. You can increase the speed of the avatar animation when the camera speed increases.

Code:

import viz
viz.go()

viz.add('tut_ground.wrl')

avatar = viz.add('vcc_female.cfg')
avatar.state(1)

import vizcam
camera = vizcam.KeyboardCamera(forward=viz.KEY_UP,backward=viz.KEY_DOWN,turnRight=viz.KEY_RIGHT,turnLeft=viz.KEY_LEFT)
viz.cam.setHandler(camera)

view = viz.MainView
link = viz.link(view, avatar)
link.preTrans([0,-1.8,2])

def changeSpeed(key):
       
        if key == '1':
                avatar.speed(1)
                camera.sensitivity(1,1)
        elif key == '2':
                avatar.speed(1.2)
                camera.sensitivity(2,1)
        elif key == '5':
                avatar.speed(1.5)
                camera.sensitivity(5,1)
               
viz.callback(viz.KEYDOWN_EVENT,changeSpeed)


#change the state when avatar stops or starts
pos = avatar.getPosition()
def checkState():
       
        global pos
        if pos == avatar.getPosition():
                avatar.state(1)
                avatar.speed(1)
        else:
                pos = avatar.getPosition()
                avatar.state(2)
               
vizact.ontimer(.1, checkState)


Moh200jo 04-08-2009 06:25 AM

it works! thanks Jeff for your help.


All times are GMT -7. The time now is 09:12 AM.

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