View Single Post
  #1  
Old 07-01-2013, 09:18 AM
kmkm kmkm is offline
Member
 
Join Date: Jun 2013
Posts: 7
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!
Reply With Quote