• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Dawn, Gloria, Juliana, or Summer - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • 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

  • 18
    Posts
    6
    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.
     
    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:
    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