Checking for a Variables Radius

I currently have a fishing game I'm making, and if the Y of your cursor matches that of the Y of the fish it moves the fish closer to being captured.

But its a little *too* precise. The game otherwise works perfectly,

Is there anyway to check for a radius of a variable? As in, say the fish is at Y10, and my variable is at Y15, how would I tell the conditional branch to fire if my variable is within X of the variable I'm trying to match?
Math.abs() returns the absolute value of a number.

So you could do if (Math.abs(fishY-cursorY)<=5) to have it execute if your cursor is within 5 either direction from your fish.
that is basic mathematics - but the formula you'll need is a bit complex to recreate by eventing.

c would be the radius or the distance, with a and b the distance in x and y coordinates
Math.abs() returns the absolute value of a number.

So you could do if (Math.abs(fishY-cursorY)<=5) to have it execute if your cursor is within 5 either direction from your fish.

just to confirm, this code I can paste into a conditional branch script and it should work? Shouldn't where fishY and cursorY be numbers?
Shouldn't where fishY and cursorY be numbers?
...yes, they will need to be the variables holding the Y values of your fish and your cursor...

If you don't know how to do that, it's $gameVariables.value(X) where X is the ID of the variable.
...yes, they will need to be the variables holding the Y values of your fish and your cursor...

If you don't know how to do that, it's $gameVariables.value(X) where X is the ID of the variable.
This works, thank you Turan.

I apologize if my follow up question seemed dumb or like I should have known.
It was a little silly to ask if they should be numbers, a better question would've been to ask how to use your variables as the numbers (since you demonstrated you knew how to put the numbers into variables) 😉

But even when you do something silly, you shouldn't apologize for not knowing things.

Original thread: https://forums.rpgmakerweb.com/threads/checking-for-a-variables-radius.140663/