• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Scripting Question] How to check the mouse is in radial area instead of a rect

19
Posts
4
Years
Is there any logic or algorithm to solve my problem, I know programming and Ruby but not professional and experienced.
So, if you know please tell me, your answer will be appreciated.
 

Luka S.J.

Jealous Croatian
1,270
Posts
15
Years
If a circle is all you want, you don't even need to do any fancy math.
Code:
dist_x = Math.abs(target_x - mouse_x)
dist_y = Math.abs(target_y - mouse_y)
radius = Math.sqrt(dist_x ** 2 + dist_y ** 2)

# to check if mouse is in a circle of radius 'r' around the target X and Y coordinates, simply check for
# if radius <= r
 
Last edited:
19
Posts
4
Years
If a circle is all you want, you don't even need to do any fancy math.
Code:
dist_x = Math.abs(target_x - mouse_x)
dist_y = Math.abs(target_y - mouse_y)
radius = Math.sqrt(dist_x ** 2 + dist_y ** 2)

# to check if mouse is in a circle of radius 'r' around the target X and Y coordinates, simply check for
# if radius <= r

Thanks it works
,but abs is not a method of math module ,i think it is of fixnum or it's super class.
ex= -300.abs=>300 ,while Math.abs(-300) gives me error in ruby or rgss.
 
Last edited:
Back
Top