View Single Post
  #2  
Old 02-10-2004, 11:14 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi Luca,

Here is some sample code that uses the keyboard for navigation, let me know if this is not what you are looking for:
Code:
import viz

viz.go()

def mytimer(num):
	if viz.iskeydown(viz.KEY_UP):
		viz.move(0,0,0.1)
	elif viz.iskeydown(viz.KEY_DOWN):
		viz.move(0,0,-0.1)
		
	if viz.iskeydown(viz.KEY_RIGHT):
		viz.rotate(viz.BODY_ORI,1,0,0)
	elif viz.iskeydown(viz.KEY_LEFT):
		viz.rotate(viz.BODY_ORI,-1,0,0)

viz.callback(viz.TIMER_EVENT,mytimer)
viz.starttimer(0,0.01,viz.FOREVER)
In regards to the < operator, you are hitting a rounding error. To see what I'm talking about have python print out more decimal places:
Code:
a = 7.0 
for x in range(10): 
	a = a + 0.1 
	print(a<7.5) 
	print '%.20f'%a
To fix this you could round off a to the nearest tenth of a decimal:
Code:
a = 7.0 
for x in range(10): 
	a = a + 0.1 
	print(round(a,1)<7.5)
	print a
Hope that explains it.
I'm honestly not sure why that 0.016 is in there, but you can control the velocity by adjusting the variable FORWARD_SPEED which is declared near the top of the script. Good luck!
Reply With Quote