WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 07-01-2013, 10: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
  #2  
Old 07-01-2013, 08:02 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
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.
Reply With Quote
Reply

Tags
joystick, navigation speed, tasks

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
joystick position nmohandes Vizard 2 01-16-2012 11:03 AM
[New here] Cave joy navigation esuna114 Vizard 2 06-11-2010 05:36 PM
changing the gain of a joystick during a program Saz Vizard 4 06-25-2009 04:49 AM
Joystick Navigation Vinicius Lima Vizard 7 10-23-2007 11:42 AM
Basic Joystick Navigation Question Plasma Vizard 2 01-29-2004 08:08 PM


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


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