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 ;)
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)) {
...
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.
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
Thanks guys!
it works now, my myyysticcc prrroooojjjeeccct!!! thx for all the help :)