Symbol_

Veteran
Veteran
Joined
Nov 28, 2017
Messages
151
Reaction score
22
First Language
English
Primarily Uses
RMMV
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?
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,248
Reaction score
1,204
First Language
English
Primarily Uses
RMMV
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.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
33,931
Reaction score
8,607
First Language
German
Primarily Uses
RMMV
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
 

Symbol_

Veteran
Veteran
Joined
Nov 28, 2017
Messages
151
Reaction score
22
First Language
English
Primarily Uses
RMMV
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?
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,248
Reaction score
1,204
First Language
English
Primarily Uses
RMMV
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.
 

Symbol_

Veteran
Veteran
Joined
Nov 28, 2017
Messages
151
Reaction score
22
First Language
English
Primarily Uses
RMMV
...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.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
2,248
Reaction score
1,204
First Language
English
Primarily Uses
RMMV
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) :wink:

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

Latest Threads

Latest Posts

Latest Profile Posts

Woot got a promotion and a pay rise ᕙ( • ‿ • )ᕗ now I'm set.
does anyone feel like explaining to me the difference between simulation and emulation? you have my full permission to be as pedantic as you want.
About the Deer, I had to cut some piece of video due the *swearing* Youtube copyrights issues...
A caveman pokes his head in...
I was listening to songs by Chuck E Cheese's voice actor (Jaret Reddick from Bowling for Soup) when the meds I was taking for my stomach virus apparently stopped working. I can't take my next dose until morning, but it's no use anyway. I'm officially sick again. Of course, I'll definitely take the next dose either way, but it's useless now.

Forum statistics

Threads
116,006
Messages
1,094,860
Members
151,311
Latest member
OpenWings
Top