Symbol_

Veteran
Veteran
Joined
Nov 28, 2017
Messages
147
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,231
Reaction score
1,194
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,911
Reaction score
8,603
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
147
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,231
Reaction score
1,194
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
147
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,231
Reaction score
1,194
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 Profile Posts

you know, some days you get resentful that game dev is even considered a "fun job" and other days it's like, welp, time to roll up my sleeves and code these molotov cocktails
If you suck at playing trumpets, that is probably why.
Been sick with a stomach virus for seven days now. Not going to work tomorrow because I'm still contagious according to my doctor.
Much as I love my job, I really hate playing "office politics". It would be nice if I didn't have to pretend to be someone else all day long.
I wanna get back into showing off Battlers and other assets I create again. But i'm always haunted by the "It's not good/realistic enough" voices that keep me from doing so.

Maybe I should get back to it, I did enjoy showing off whatever I came up with!

Forum statistics

Threads
115,958
Messages
1,094,385
Members
151,223
Latest member
leolotus
Top