WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   linking view to avatar (https://forum.worldviz.com/showthread.php?t=1975)

5ky1ine 04-21-2009 03:48 AM

linking view to avatar
 
is ther any way of linking the view to an avatar and walk around the environment using the keyboard like in a game?

any help will be really appreciated..

Moh200jo 04-21-2009 06:41 AM

try the following code to link the avatar with the mainview
HTML Code:

mainview=viz.clearcolor(viz.SKYBLUE)
avatar = viz.add('vcc_female.cfg')
avatar.setPosition(0,0,9)
view = viz.MainView
link = viz.link(avatar, view)
link.preTrans([0,-0.5,-5])


Moh200jo 04-21-2009 07:11 AM

I correct this what you are looking for.
HTML Code:

import viz
import vizcam
viz.go()
viz.add('tut_ground.wrl')
avatar = viz.add('vcc_female.cfg')
avatar.state(2)
handcontrol = vizcam.KeyboardCamera(forward=viz.KEY_UP,backward=viz.KEY_DOWN,turnRight=viz.KEY_RIGHT,turnLeft=viz.KEY_LEFT)
viz.cam.setHandler(handcontrol)
view = viz.MainView
link = viz.link(view, avatar)
link.preTrans([0,-1.5,5])
pos = avatar.getPosition()


5ky1ine 04-21-2009 08:04 AM

thanks for the reply,

the code works fine apart from the avatar is in the walking state even when you are not pressing anything. is there anyway to make the avatar stand still when no key is being pressed?

Moh200jo 04-21-2009 09:08 AM

yes just define a function to check the avatar state

5ky1ine 04-21-2009 09:17 AM

can you tell me how that is done please

thanks

Moh200jo 04-21-2009 09:39 AM

I correct something like this:
HTML Code:

avatar_position = avatar.getPosition()
def avatarstate():
        global avatar_position
        if avatar_position == avatar.getPosition():
                avatar.state(1)
        else:
                avatar_position= avatar.getPosition()
                avatar.state(2)
               
vizact.ontimer(.05, avatarstate)

I hope this will be helpful

5ky1ine 04-21-2009 11:03 AM

Thanks that worked, but only one thing left, the avatar dosent have collision, it walks through the walls and other objects. any suggestions


All times are GMT -7. The time now is 03:07 PM.

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