1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

[DnD] Mouse Object Actions in Range

Discussion in 'Programming' started by TheAlmighty, May 16, 2019 at 11:05 PM.

  1. TheAlmighty

    TheAlmighty Member

    what would be the easiest approach to achieve mouse targeting like this? in a certain radius and actually hitting the rock your next to, was thinking even with the gml instance_find_nearest() approach it will still hit a random node

    furthest i've got is i'm able to break the rock but if i'm standing next to one i can mine any node in sight, range isnt becomming a factor.
  2. Nocturne

    Nocturne Friendly Tyrant Forum Staff Admin

    Apr 13, 2016
    You want to get the instance_position under the mouse, then check the distance from the player... There is no DnD for the distance, but it's easy enough with the DnD "Function Call" action (https://docs2.yoyogames.com/index.h...p_reference/common_actions/function_call.html) and the GML function "distance_to_object". So, you call something like "If Collision Point" (https://docs2.yoyogames.com/index.h...nce/collision_actions/if_collision_point.html) using mouse_x/mouse_y as the position, and you store the returned ID in an instance variable. You then check the distance to this instance using the Function Call and the distance function. If the distance is less than whatever value you require, then it's selected and if it's not then it's not.

    Hope that helps!
    Toque likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice