WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Changing Joystick navigation halfway through (https://forum.worldviz.com/showthread.php?t=4661)

kmkm 07-01-2013 09:18 AM

Changing Joystick navigation halfway through
 
Hi there,

In this setup, the user must navigate using a joystick. When the viewpoint collides with an invisible torus, I want the joystick navigation speed to change. Everything else in the simulation runs on a sequence of tasks, so I tried creating a variable and changing it in one of the tasks, but it's not working. Here's what I have so far:

import vizjoy
joystick = vizjoy.add()

randommove = random.uniform(.01, .0300) # Random float x, 1.0 <= x < 10.0
randommove2 = random.uniform(.001, .0002)

def mytimer(num): #configure joystick navigation
global MOVESPEED
MOVESPEED = randommove
y = sid.get()[1]
x = sid.get()[0]
twist = (180.0 / math.pi) * (sid.aux()[3])
if math.fabs(y) > 0.5:
viz.move(0,0,-y*MOVESPEED)
if math.fabs(x) > 0.5:
viz.move(x*MOVESPEED,0,0)
if math.fabs(twist) > 20:
viz.rotate(viz.BODY_ORI,twist/50.0,0,0)

viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.001,viz.FOREVER)


def update_mytimer_task():
yield viztask.waitEvent( viz.COLLISION_EVENT )
global MOVESPEED
MOVESPEED = randommove2


def torus_collision_task():
yield viztask.waitEvent( viz.COLLISION_EVENT ) #colliding with the #torus also causes a blank screen to appear with instructions

def train():
blank_screen.visible( viz.OFF )
torus_collision = viztask.waitTask( torus_collision_task() )
update_mytimer = viztask.waitTask( update_mytimer_task() )
data = viz.Data()
yield viztask.waitAll( [torus_collision, update_mytimer] )
blank_screen.visible( viz.ON )
blank_screen.alpha(.6)
text2 = viz.addText('Reproduce the distance you just walked \n\nand press "s" when finished',viz.SCREEN)
text2.alignment( viz.TEXT_CENTER_CENTER )
text2.setPosition( .5,.5 )
text2.setScale(.5,.5)
text2.color(viz.YELLOW)
text2.setBackdrop(viz.BACKDROP_RIGHT_BOTTOM)
text2.resolution(1)
text2.alpha(1)
sphere.visible(viz.OFF)
yield viztask.waitTime( 2 )
blank_screen.visible(viz.OFF)
text2.visible(viz.OFF)
torus.remove()

any ideas for getting the navigation speed to change after the collision?

thanks!

Jeff 07-01-2013 07:02 PM

Please wrap code with code tags to preserve indentation. Here's some example code that changes the speed based on a collision with an object that is not rendered:
Code:

torus = vizshape.addTorus(pos=[0,1.8,4])
torus.disable(viz.RENDERING)

def onCollision(info):
        if info.object == torus:
                moveSpeed += 1

viz.callback(viz.COLLISION_EVENT, onCollision)

If you use torus.visible(viz.OFF) the collision event will not get generated.


All times are GMT -7. The time now is 01:38 AM.

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