Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: geork on Wed 27/05/2009 22:00:52

Title: One character close to other respons problem
Post by: geork on Wed 27/05/2009 22:00:52
 Hey All!
   I'm trying to trigger an event when one character gets close to the other (say about, 5x and 5y away). I tried the "IsCollidingWithChar" method:
                 
                if(cChar1.IsCollidingWithChar(cEgo) == 1)//tried to also put in numbers like 50 etc
               

                 but one character just walks round the other. I also tried the "AreThingsOverlapping", but that seems to only work with objects.
                Is there a way to solve this?
                   Thanks ;)
Title: Re: One character close to other respons problem
Post by: Khris on Wed 27/05/2009 23:29:37
AreThingsOverlapping() should work, just keep in mind to pass the characters' IDs:
  if (AreThingsOverlapping(player.ID, cGuy.ID)) { ...
Since it does a rectangular check, it doesn't work well for checking the distance though.

I think .IsCollidingWithChar checks the BlockingWidth/Height of the two characters. So if both characters are .Solid, this might never be true.

The arguably best way is calculating the distance of their positions:

bool CloseTo(this Character*, Character c, int dist) {
  int x = this.x - c.x, y = this.y - c.y;
  return x*x + y*y <= dist*dist;
}

// inside rep_ex
  if (player.CloseTo(cGuy, 5)) {
    ...
Title: Re: One character close to other respons problem
Post by: Wonkyth on Wed 27/05/2009 23:38:07
You could probably do something with SSHes PixelPerfect Collision Detection module, I had a look at it recently, and it probably wouldn't take much retrofitting to get it to do that.
Title: Re: One character close to other respons problem
Post by: Trent R on Thu 28/05/2009 00:22:17
Quote from: wonkyth on Wed 27/05/2009 23:38:07
You could probably do something with SSHes PixelPerfect Collision Detection module, I had a look at it recently, and it probably wouldn't take much retrofitting to get it to do that.
But Pixel Perfect is literally Pixel Perfect, and therefore a lot slower. Besides, it's already based off of the existing functions.

But our good old friend Pythagoras is the easiest and best solution.

~Trent
Title: Re: One character close to other respons problem
Post by: geork on Thu 28/05/2009 01:06:51
Thanks guys!
  it works now, my myyysticcc prrroooojjjeeccct!!! thx for all the help :)