View Single Post
  #1  
Old 08-20-2009, 08:11 AM
ptjt255 ptjt255 is offline
Member
 
Join Date: Oct 2008
Posts: 24
Start_position on animation path

Hi,

Currently, I have the start position set at [2.0, 1.0, 0.0], but what I really want is for the start position to be wherever the avatar happens to be on the animation path, any help would be really appreciated.

Code:
# Creates and animation path for the avatar
path = viz.addAnimationPath()

points = [[2.0,1.5,0.0],[2.0,1.0,0],[2.0,0.0,0]]

for move in range(len(points)):
	global move
	cp = viz.add(viz.CONTROL_POINT)
	cp.translate(points[move])
	path.add(cp,2.0*move)
	print move

path.loop(viz.SWING)
path.constantspeed(viz.ON,0.5)

avatar.link(path)

# Link the avatar to the joystick and track position and elapsed time
# Defines collision parameters and avatar action on collision

import time

# Variables
result = 0 
tinc = 1/100
# from avatar to target the distance is 3.5m
joyscale_x = 1.40 # scale max x joystick velocity to 1.125 m/s maximum (roughly the time it takes to cross a single lane of a road) - 4 seconds to cross 4.5 meters which is 1.5 seconds per meter
joyscale_y = -1.40 # scale max y joystick velocity to 1.125 m/s maximum (roughly the time it takes to cross a single lane of a road)
start_position = [2.0, 1.0,0]

def position_loop():
	global start_position, result, x_prev, y_prev, x_velocity, y_velocity, ctime, ij, cframe, y_pos, x_pos, x, y, joy_position, i, select, p, ctime, pos_inc, start_position,elapsed_time,tinc
	x_velocity = 0.0
	y_velocity = 0.0
	x_prev = start_position[0]
	y_prev = start_position[1]
	#print 'y previous:', y_prev, 'x previous', x_prev
	Start_tick = time.time()
	cframe = 0

	def mytimer(tinc): 
		global result, x_prev, y_prev, ctime, ij, cframe, y_pos, x_pos, x, y, joy_position, i, select, p, ctime, x_velocity, y_velocity, elapsed_time
		# Set up joystick as velocity control
		ctime = time.time() - Start_tick
		cframe = cframe+1
		x = x_prev + x_velocity/60; y = y_prev + y_velocity/60
		avatar.setPosition(x,y)
		joy_position = joystick.getPosition()
		x_prev = x; y_prev = y;
		x_velocity = joyscale_x*joy_position[0]; y_velocity = joyscale_y*joy_position[1]
		elapsed_time = time.time() - Start_tick
Reply With Quote