WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #8  
Old 10-07-2018, 07:50 PM
hannahapz hannahapz is offline
Member
 
Join Date: Apr 2018
Posts: 22
Revisit

So I've managed to use the distance function to inform me of when my cars get too close to one another, and I've managed to speed up the lead car/slow down the tailing car to simulate realistic driving, but the problem I'm having is with my nested if loops.

Code:
# function that has cars move at a trajectory of, in this example, 10 m/s)
def moving_cars():
	global elapsedTime, z, obs_car
	for i, item in enumerate(my_entire_car_list):
		item.add(vizact.move(0, 0, 10)

# function ensures cars adjust speeds if they get within a certain distance of one another (lead car speed up and tail slows)			
def track_A_moving_cars():
	global track_A, track_B, track_C
	for i in range(len(track_A)):
		for a in track_A[i+1:]:
			if vizmat.Distance(track_A[i].getPosition(), a.getPosition()) < 30.0:
				if track_A[i].getPosition()[2] < a.getPosition()[2]:
					a.add(vizact.move(0, 0, 3, 1), 0)
					track_A[i].add(vizact.move(0, 0, -10, 2), 1)
					
				elif track_A[i].getPosition()[2] > a.getPosition()[2]:
					a.add(vizact.move(0, 0, -10, 2), 2)
					track_A[i].add(vizact.move(0, 0, 3, 1), 3)
EXAMPLE OF MY PROBLEM: targeted tail car will slow down, then resume regular speed, slow down again, resume regular speed, etc. I'm assuming this is because o fmy nested if within nested for loop. I've set the function to run every frame. How do I restart the function?

Any help would be greatly appreciated.

Last edited by hannahapz; 10-07-2018 at 07:59 PM. Reason: Incomplete initial response
Reply With Quote
 


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
Picking up Vizard Objects on mouse down with collisions pwsnow Vizard 2 09-17-2012 02:02 AM
Trouble picking text3d objects Salvar Vizard 4 12-01-2010 03:07 PM
static or dynamic objects shahramy Vizard 2 11-10-2010 12:32 AM
Semi-circle array containing target and distractor objects ptjt255 Vizard 3 08-04-2009 03:09 AM
Could not find plugin to load objects... halley Vizard 1 05-30-2006 11:01 AM


All times are GMT -7. The time now is 07:59 AM.


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