PDA

View Full Version : Avatar walk


betancourtb82
03-15-2006, 10:49 AM
I was wondering if you could help me with this problem. I think it's more of a mathematical problem but I think it applies to programming. I need for avatars to appear from all directions instead of just in front of the person participating in the experiment. I can't seem to figure out how to set up my x,y,z to have this occur. We want avatars to appear from all directions and have the user actually have to look around to see where they are coming from.

Here is what I have so far:

for i in range(NUM_AVATARS):
newX = -math.cos(-2*i+15) * 2
newZ = math.sin(45*i) * 10
male = viz.add('male.cfg')
male.translate(newX,-10,newZ)
male.rotate(180,0,0)
avatars.append(male) #Save avatar in list

The interval that they appear is set by a timer. Here is that portion of the code.

def mytimer(num):
global avatars
if num == ANIMATION:

#Calculate elapsed time since last update
elapsed = viz.elapsed()

#Update each active ball
for bullet in bullets:
if bullet.active:
#Move the ball and check if it has collided with any objects
MoveBullet(bullet,elapsed)

elif num == START_AVATAR:
global nextAvatar
#Get the next available avatar and start it
avatar = avatars[nextAvatar]
#favatar = favatars[nextAvatar]
walkAvatar(avatar)
#walkAvatar(favatar)
nextAvatar = (nextAvatar + 1) % NUM_AVATARS
viz.starttimer(START_AVATAR,TIME_BETWEEN_AVATARS)


#Restore next available avatar
vizact.onkeydown(' ',RestoreAvatar)

#Shoot a ball whenever left mousebutton is clicked
vizact.onmousedown(viz.MOUSEBUTTON_LEFT,shootBulle t)

#Create callbacks for timer events
viz.callback(viz.TIMER_EVENT,mytimer)

farshizzo
03-15-2006, 02:01 PM
Hi,

Can you be more specific on where you want them to appear. Can you just select random coordinates within a certain range?

betancourtb82
03-19-2006, 01:56 PM
I would like for them to appear within a radius of the subject. I want them to appear in front, to the left and right and behind the subject and certain intervals. They don't have to be random to the programmer, but appear random to the user. In other words, the order they appear is not important. So, basically, what I need to do is have them appear around the user coming in from all directions.

farshizzo
03-20-2006, 02:10 PM
Hi,

The following code will compute a random position within a certain radius.#Get random direction
angle = viz.radians(vizmat.GetRandom(0,360))

#Get random radius between 5 and 10
radius = vizmat.GetRandom(5,10)

#Compute position
x = math.sin(angle) * radius
z = math.cos(angle) * radius

betancourtb82
03-21-2006, 09:06 AM
Thanks! That really

betancourtb82
03-21-2006, 09:14 AM
Thanks! That really helped out