PDA

View Full Version : Smart Collision Detection


atomega
10-24-2006, 07:24 AM
i have an idea for collision detection that seems great, but somehow it doesn't work:

I have a gun, an invisible bullet and a target: when firing i do this:

// all durations == 0
//
Fire( Object target) {
Number distance;

distance= gun.distanceTo( target);
bullet.moveTo( gun);
bullet.orientTo( gun.barrel);
bullet.move( FORWARD, distance);

if( bullet.distanceTo( target) < 1){
target.say( "that hurts!);
}
}

what happens is that if i miss the target, the bullet hits the ground and stops there. shouldn't it always move the same distance?

any ideas would be welcome!

/atomega

DrJim
10-24-2006, 10:03 AM
What you described worked fine for me (and is a neat trick :) ) once I got the orientations straight. See the attached file. Even when I was always missing, the "bullet" always went the same distance. (It would go through the ground if I was aiming that way.)

Kirbya
10-25-2006, 02:56 PM
In the world you posted above DrJim what is the object bulletStart? It only have a vehicle property and a pointofview property..

DrJim
10-25-2006, 07:26 PM
That was a "dummy object" that I renamed. You can get them by moving a real object to where you want to save the point of view and then using the "drop dummy at selected object" button after using the "more controls" option in the Add Object window. Unfortunately, Alice doesn't put a very meaningful name on the dummy object so to keep track, you have to rename it right away.

Did you get your code working?

atomega
10-27-2006, 06:41 AM
Yes, thanks drJim:
By changing the orientTo()-parameter from gun.barrel to (the entire) gun.

You can also use setPointOfView( gun.getPointOfView() ) instead of
moveTo() and orientTo().


/n

DrJim
10-27-2006, 11:23 AM
You're right - the single call is equivalent and more compact and should be used in any production code. I did it in two steps since I was trying to debug the problem and didn't take the time to "productize" the code.

javatexan
08-15-2009, 02:28 AM
Is there a way to figure out the current viewable area of the camera? I am trying to artificially create an area in which my actors have to stay. I would like to have the camera pan to follow actors and/or zoom to a threshold and I would like to be able to keep all actors above the ground. ;)

In other systems this is accomplished by wall and ground collisions. Any ideas on how to simulate this in Alice?

Thanks.