View Single Post
  #5  
Old 10-18-2010, 08:47 AM
just alex just alex is offline
Member
 
Join Date: Nov 2008
Posts: 18
Sorry, i had a case of the dumb and posted an old code I was messing with. This should all be with general stuff so you shouldn't need to make any alterations. All I really need is for the avatars to walk around continuously to create a little veracity in my city.
Code:
import viz
import math
import vizmat
import vizinfo
import vizact
viz.go()



#Add the street and drop it a little bit to be below the avatars feet.
street = viz.add('tut_ground.wrl')
street.translate(0,-.2,0)



females = []
walking = []
whichturn = 0

#List the timers.
WALKING = 0

HOLDVIEW = 8
TIMING = 9



for i in range(1):
	female = viz.add('vcc_female.cfg')
	female.translate(i,0,0)
	females.append(female)




#Set up paramters for walking girl.
females[0].translate(1,0,-7)
females[0].rotate(0,1,0,-90)
females[0].whichturn = 0
females[0].set = [[1.5,0,0],[1,0,15],[2,0,15],[-5,0,-5]]
females[0].end = 3
walking.append(females[0])

#Add car.
car = viz.add('mini.osgx')

#set car stuff
car.translate(-1.5,0,8)
car.rotate(0,1,0,180)









#Set up for timing.
timebomb = 0


def onkeydown(key):
	if key == '0':
		viz.starttimer(WALKING, .1, viz.PERPETUAL)
	

		
def ontimer(num):
	global gravity, timebomb
	

	if num == WALKING:
		for agent in walking:
			agentposition = agent.get(viz.POSITION)
			agentgap = vizmat.Distance(agentposition, agent.set[agent.whichturn])
			if agentgap < .1:
				agent.whichturn += 1
				if agent.whichturn == agent.end:
					agent.whichturn = 0
			
			walk = vizact.walkto(agent.set[agent.whichturn][0],agent.set[agent.whichturn][1],agent.set[agent.whichturn][2])
			agent.addAction(walk)
			

	
	if num == HOLDVIEW:
		view.translate(-8.5,1.5,-2)
		
	if num == TIMING:
		print timebomb
		timebomb += 1
		
		if timebomb == 1:
			onkeydown('0')
			
		elif timebomb == 3:
			onkeydown('8')
		
		elif timebomb == 10:
			onkeydown('9')
		
		elif timebomb == 20:
			onkeydown('3')
		
		elif timebomb == 30:
			onkeydown('1')
		
		elif timebomb == 80:
			viz.quit()
	
viz.callback(viz.TIMER_EVENT,ontimer)

viz.callback(viz.KEYDOWN_EVENT,onkeydown)
viz.starttimer(HOLDVIEW,.001, viz.PERPETUAL)
Reply With Quote