In my game Bob's busking nightmare, there are a few instances where bob is busking and the police come to hassle him.
at the moment I have used collisions etc but it is not what I am looking for.
It would be better if a few yards away from the player the police hassle script jumps in, that is before a collision. maybe using regions.
How can I have a script which detects that player is in same region as the policeman???
Something like:
if (Region.GetAtRoomXY(player.x, player.y)==Region.GetAtRoomXY(cPolice.x, cPolice.x)) {
Ã, blah blablabla
}
You also might want to make sure that those aren't both null (just checking one would work) because if they are both null then it would return true...
Regions are the best choice if there's a specific spot Bob will be standing on to busk (e.g. he moves there when you start him busking). However, if he can just start playing wherever he's stood, you might be better just checking against the character's coordinates, e.g.:
if (cPolice.x > (cBob.x-75) && cPolice.x < (cBob.x+75)) {
// Start hassling
}
This would start the hassling if the Police character was less than 75 pixels left or right of Bob. Depending on the background(s) used, you could also add a check on the Y position.
thanks everyone it works as I wanted, in fact ive put regions on all the relevant areas so that bob is hassled if the police are within haearing distance about 75 pixels away. I'm now very happy until my next problem
lol