View Single Post
  #4  
Old 09-15-2008, 04:02 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
you could create a callback function that is called every time a timer expires. Within that function you could get the position of your cars and calculate the distance between them. If they are to close you could speed up the one in front and slow down the one behind.

Code:
import vizmat

#start a timer that will call onTimer() every 2 seconds
viz.starttimer(0,2,viz.FOREVER)

def onTimer(num):
	

	car1_Pos = car1.getPosition()
	car2_Pos = car2.getPosition()
	distance = vizmat.Distance(car1_Pos, car2_Pos)
	
	if distance is too close:
	
		#increase speed of path of car1
		#decrease speed of path of car2
		
		
		
viz.callback(viz.TIMER_EVENT,onTimer)

is that helpful?
Reply With Quote