PDA

View Full Version : Walking avatars --> collision detection?


sjroorda
09-12-2005, 05:01 AM
Currently I am working on a scene in which I as viewer am surrounded by a lot of walking people (the default avatars).

However, the walkto-command sometimes lets an avatar walk through 'myself', resulting in a jump of the viewpoint (due to the collision detection). In what way is it possible to solve this problem (proposed it is possible!)? I can mess a little with the coordinates I send the character to, but as I can walk freely through the scene, this cannot be guaranteed.

Another problem is avatars walking through each other. Don't they have any collission detection?

And to ask my last question: is it possible to group avatar objects into an array? Take a look at my code below and you'll understand why :).

See an example piece of code below:

import viz
import whrandom

# Handles all timer events for the therapist machine
def mytimer(num) :
if (num == 1) :
view_pos = view.get(viz.HEAD_POS);
a1.act(a1.walkto(view_pos[0] + whrandom.randint(-2, 3), 0, view_pos[2] + whrandom.randint(-2, 3)));
a2.act(a2.walkto(view_pos[0] + whrandom.randint(-2, 3), 0, view_pos[2] + whrandom.randint(-2, 3)));
a3.act(a3.walkto(view_pos[0] + whrandom.randint(-2, 3), 0, view_pos[2] + whrandom.randint(-2, 3)));
a4.act(a4.walkto(view_pos[0] + whrandom.randint(-2, 3), 0, view_pos[2] + whrandom.randint(-2, 3)));
a5.act(a5.walkto(view_pos[0] + whrandom.randint(-2, 3), 0, view_pos[2] + whrandom.randint(-2, 3)));
a6.act(a6.walkto(view_pos[0] + whrandom.randint(-2, 3), 0, view_pos[2] + whrandom.randint(-2, 3)));
a7.act(a7.walkto(view_pos[0] + whrandom.randint(-2, 3), 0, view_pos[2] + whrandom.randint(-2, 3)));
a8.act(a8.walkto(view_pos[0] + whrandom.randint(-2, 3), 0, view_pos[2] + whrandom.randint(-2, 3)));
a9.act(a9.walkto(view_pos[0] + whrandom.randint(-2, 3), 0, view_pos[2] + whrandom.randint(-2, 3)));

viz.go(0);
view = viz.get(viz.MAIN_VIEWPOINT);

# Create the room and make it a bit larger
myroom = viz.add('../room/room.wrl');
myroom.scale(10, 3, 10);

# Set background color
viz.clearcolor(0, 0, 0);

# Turn on collision detection
viz.collision(viz.ON);
viz.stepsize(0);

# Test moving avatars
a1 = viz.add('female.cfg'); a1.translate(1, 0, 1);
a2 = viz.add('female.cfg'); a2.translate(1, 0, 1);
a3 = viz.add('female.cfg'); a3.translate(1, 0, 1);
a4 = viz.add('female.cfg'); a4.translate(1, 0, 1);
a5 = viz.add('female.cfg'); a5.translate(1, 0, 1);
a6 = viz.add('male.cfg'); a6.translate(1, 0, 1);
a7 = viz.add('male.cfg'); a7.translate(1, 0, 1);
a8 = viz.add('male.cfg'); a8.translate(1, 0, 1);
a9 = viz.add('male.cfg'); a9.translate(1, 0, 1);

viz.callback(viz.TIMER_EVENT, mytimer);
viz.starttimer(1, 1, viz.FOREVER);

farshizzo
09-12-2005, 09:16 AM
Hi,

There is no built-in way to prevent avatars colliding with each other or having them collide with the viewpoint. You will have to perform this collision check manually. You could create a timer that checks if two avatars are a certain distance from each other and stop them if they are. You could do the same with the viewpoint too.

Here is some code to use arrays to create your avatars:#Create the avatars
avatars = []
for x in range(9):
a = viz.add('female.cfg')
a.translate(1,0,1)
avatars.append(a)

#Have all the avatars walk
for a in avatars:
a.act(a.walkto(view_pos[0] + whrandom.randint(-2, 3), 0, view_pos[2] + whrandom.randint(-2, 3)))

Veleno
09-15-2005, 05:06 PM
A thought on this problem came to mind --

Since avatars do not detect collision with each other, how about giving them something to collide with?

It would seem to me that it could be possible to have each avatar (and the viewpoint) surrounded with invisible rectangular prisms (or octagonal for a more "round" fit) that follow them wherever they go.

If avatar A gets to close to avatar B, then avatar A will be stopped by the prism surrounding avatar B.

Eunice
10-13-2005, 04:47 AM
This is called 'the bounding volume' method in collision dection.

Originally posted by Veleno
It would seem to me that it could be possible to have each avatar (and the viewpoint) surrounded with invisible rectangular prisms (or octagonal for a more "round" fit) that follow them wherever they go.

If avatar A gets to close to avatar B, then avatar A will be stopped by the prism surrounding avatar B.