GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Script Submission » instance_nearest_dir » 2017-10-17 16:55:03

r0wan
Replies: 0
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;

#2 Re: Script Submission » instance_nearest_multiple » 2017-08-26 08:53:57

Oh, I didnt see that; I guess it should be using point_distance then -

Expand///instance_nearest_multiple(x,y,object1,object2,etc...);
//
//gets the nearest instance out of multiple types of objects
//
//
//      x      the x position to check from
//      y      the y position to check from
//      object1 - etc...       object type to check for
//
/// GMLscripts.com/license

var _x = argument[0];
var _y = argument[1];
var r = instance_nearest(_x, _y, argument[2]);
var rd = point_distance(_x,_y,r.x,r.y);
for (var i = 3; i < argument_count; i++) {
    var q = instance_nearest(_x, _y, argument[i]);
    var qd = point_distance(_x,_y,q.x,q.y);
    if (qd < rd) { rd = qd; r = q; }
}
return r;

#3 Script Submission » instance_nearest_multiple » 2017-08-17 17:07:00

r0wan
Replies: 2
Expand///instance_nearest_multiple(x,y,object1,object2,etc...);
//
//gets the nearest instance out of multiple types of objects
//
//
//      x      the x position to check from
//      y      the y position to check from
//      object1 - etc...       object type to check for
//
/// GMLscripts.com/license

var _x = argument[0];
var _y = argument[1];
var r = instance_nearest(_x, _y, argument[2]);
var rd = distance_to_object(r);
for (var i = 3; i < argument_count; i++) {
    var q = instance_nearest(_x, _y, argument[i]);
    var qd = distance_to_object(q);
    if (qd < rd) { rd = qd; r = q; }
}
return r;

Board footer

Powered by FluxBB