GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2017-10-17 16:55:03

r0wan
Member
Registered: 2017-08-17
Posts: 3

instance_nearest_dir

Expand///instance_nearest_dir(x,y,obj,dir,min,max);
//
// gets the nearest instance in a direction within a range of dir - min to dir + max degrees
//
//
//      x      the x position to check from
//      y      the y position to check from
//      obj    the object type to check for
//      dir    the direction to check within 90 degrees of
//      min    the ammount less than the direction to check
//      max    the ammount more than the direction to check
//
/// GMLscripts.com/license

var _x = argument[0];
var _y = argument[1];
var _obj = argument[2];
var _dir = argument[3];
var _min = argument[4];
var _max = argument[5];

var _nearst = noone;
var _nearstdist = 0;

with(_obj){
    var _nearst_point_dir = point_direction(_x,_y,x,y);
    var _nearst_point_dist = point_distance(_x,_y,x,y);
    show_debug_message(string(angle_difference(0,_nearst_point_dir)) + "ang");    
    if(angle_difference(0,_nearst_point_dir) >= _dir - _min && angle_difference(0,_nearst_point_dir) <= _dir + _max
    && (_nearst == noone || _nearst_point_dist < _nearstdist)){
        _nearst = id;
        _nearstdist = _nearst_point_dist;
    }
}

return _nearst;

Last edited by r0wan (2017-10-17 17:22:55)

Offline

Board footer

Powered by FluxBB