Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: dreammaster on Mon 30/08/2004 04:25:36

Title: Finding intersection of character and object
Post by: dreammaster on Mon 30/08/2004 04:25:36
Hi there. I'm somewhat new to AGS, although I've been programming for years. I'm trying to figure out a generic way to determine if an object collides with any part of a character, rather than just the feet (as is the case with AreCharObjColliding). Is there any such method available, or failing that, a way to get the dimensions of a sprite so I can do the collision check programmatically?

I'd prefer not to have to resort to trying to hardcode the sizes in case I later change the size of the objects.

Thanks for any help.
Title: Re: Finding intersection of character and object
Post by: strazer on Mon 30/08/2004 04:31:00
Check out the AreThingsOverlapping function in the manual.
Title: Re: Finding intersection of character and object
Post by: dreammaster on Mon 30/08/2004 11:18:51
Thanks for the quick reply. The only trouble is I'm not quite sure how to use it. The function seems to have been introduced in version 2.61, and the manual doesn't include it. And the Changelogs only say that it was added.

Code completion within AGS says that it takes two parameters - thing1 and thing2. Are these only meant to be objects? If that's the case, is there any way I can get around this?

I tried the following, using an object to represent the character:

SetObjectFrame(OBJ_PLACEHOLDER, character[EGO].view, character[EGO].loop, character[EGO].frame);
SetObjectPosition(OBJ_PLACEHOLDER, character[EGO].x, character[EGO].y);
int is_overlapping = IsObjectOn(OBJ_ROCK) && AreThingsOverlapping(OBJ_PLACEHOLDER, OBJ_ROCK);

But even that doesn't work. I'm not sure just how to get this function to work.
Title: Re: Finding intersection of character and object
Post by: Ashen on Mon 30/08/2004 12:10:23
If you're using a placeholder object anyway, why not just use AreObjectsColliding?
Anyway, my manual entry for AreThingsOverlapping says "THING1 and THING2 can either be a CHARID, or can be an object number PLUS 1000/"
So:

AreThingsOverlapping (EGO, OBJ_ROCK + 1000);

Maybe?

What is the int is_overlapping line meant to do?
Title: Re: Finding intersection of character and object
Post by: dreammaster on Mon 30/08/2004 12:58:48
Thanks it's working now. And I finally realised that a HTML help file came with the executable - I was trying to rely on the AGS 2.4 manual I downloaded separately. :). The is_overlapping variable was one I temporarily used when I was experimenting with the method. At one point I thought I'd need to turn the placeholder object on, check for collision, and then turn it off again. I'd then use the value of the variable as the condition check for my block of code to run if the player had been hit by the debris.

It's all nice and simple now. Thanks.