Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: static on Fri 11/07/2003 16:13:00

Title: How to speed up collision detection!?
Post by: static on Fri 11/07/2003 16:13:00
I've made a collision code because I wan't a character(EGO) to
trow the object(0) at another character(A)  and when the object
hits character(A) then character(A) does the 'fall' animation. Everything
works perfect except that the speed of the object must be set to
3 or less or the code doesn't catch the collision. Help

Global script

function displaynice() {
int true,playerx,objectx;
playerx=character[A].x;
objectx=GetObjectX(0);
if (playerx==objectx)    // can I here do this: (character[A].x==GetObje...)
{
 true=1;
 }
return true;
}


When character intracts with inventory to this character
(EGO throws it at A)

StopMoving (A);
SetCharacterView (EGO,2);
Wait(40);
AnimateCharacter (EGO, 0, 3, 0);
Wait(20);
ObjectOn(0);
MoveObjectDirect(0,350,160,1);


Room Repeatedly execute

if (displaynice()==1){
SetCharacterView (A, 4);
AnimateCharacter (A, 0, 5, 0);
while(character[A].animating) Wait(1);
SetGlobalInt(1,1); //It's dead. Blimey! needed for something else
SetCharacterView (EGO,1);
RestoreWalkableArea (1);
}



Now how to speed this up? If you need additional explanations
just ask
???
Title: Re:Help with collisions
Post by: SSH on Fri 11/07/2003 16:30:54
Are the two characters always in the same place when this trhowing happens, or might they be in different places? Well, anyway:

how about:

function displaynice() {
return (((character[A].x > character[EGO].x) && (GetObjectX(0) >= character[A].x)) || ((character[A].x < character[EGO].x) && (GetObjectX(0) <= character[A].x)));
}

this checks if the object was thrown from the left or right and then checks if the object has hit or passed (if going fast) the character A.
Title: Re:Help with collisions
Post by: static on Fri 11/07/2003 22:27:31
Well I've done the collision code because the character[A] is
moving all the time.

Could you explain your code? I'm just a beginner I didn't get
it. ??? :)

But character(EGO) is not mocing. Could you explain
why isn't the code catching when the object x and
character x match if the speed is too high? Does this
depend on game cycles? Is there a way to speed them
up or something?