How Have People Accomplished Proximity?

Hello! I'm trying to add something to a game where if you get close to a guard, they'll catch you. But I've had some trouble with checking how far off the player is from the guard. How have other people done proximity? Do you just check every tile around the object you want to have proximity for the player, or is there some easy way to do proximity that I'm not aware of? Thank you!

1 Like
on check do
  
  radius = 4
	
	checkx = event.x
	checkx += radius
	
	if event.px<=checkx then
		checkx = event.x
		checkx -= radius
		if event.px>=checkx then
			
			checky = event.y
			checky += radius
			
			if event.py<=checky then
		    checky = event.y
		    checky -= radius
		    if event.py>=checky then
		      say "Detected"
end
end
end
end
end

I don't know about anybody else, but this is how I've always done it; you essentially create a range, 4 less than, 4 greater than, if the player is within that range, they are within that line, do it for the other axis, and you have a square.

4 Likes

Wow, thanks! This works great, and is a lot simpler than I expected something like this would be. Thanks so much!