![]() |
|
|
|
#1
|
|||
|
|||
|
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)
|
|
#2
|
|||
|
|||
|
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) |
|
#3
|
|||
|
|||
|
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)
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Walking viewpoints | TrashcanPatrol | Vizard | 5 | 05-02-2013 10:14 AM |
| Walking Function | Moh200jo | Vizard | 2 | 02-24-2009 11:07 AM |
| How to make avatars to follow terrain while walking? | yyang | Vizard | 1 | 08-04-2008 03:54 PM |
| Walking avatars --> collision detection? | sjroorda | Vizard | 3 | 10-13-2005 05:47 AM |