Pixel-Composer/scripts/node_VFX_attract/node_VFX_attract.gml

42 lines
1.4 KiB
Text
Raw Normal View History

2023-02-28 09:43:01 +01:00
function Node_VFX_Attract(_x, _y, _group = noone) : Node_VFX_effector(_x, _y, _group) constructor {
2022-12-13 09:20:36 +01:00
name = "Attract";
2022-12-16 09:18:09 +01:00
node_draw_icon = s_node_vfx_attract;
2022-12-13 09:20:36 +01:00
2024-08-08 06:57:51 +02:00
inputs[4].setVisible(false, false);
2023-01-17 08:11:55 +01:00
2024-08-18 06:16:20 +02:00
newInput(effector_input_length + 0, nodeValue_Bool("Destroy when reach middle", self, false ));
2023-10-29 06:29:10 +01:00
array_push(input_display_list, effector_input_length + 0);
2022-12-13 09:20:36 +01:00
function onAffect(part, str) {
2023-10-10 07:12:42 +02:00
var _area = getInputData(1);
var _area_x = _area[0];
var _area_y = _area[1];
2022-12-13 09:20:36 +01:00
2023-10-10 07:12:42 +02:00
var _sten = getInputData(5);
var _rot_range = getInputData(6);
var _sca_range = getInputData(7);
var _rot = random_range(_rot_range[0], _rot_range[1]);
var _sca = [ random_range(_sca_range[0], _sca_range[1]), random_range(_sca_range[2], _sca_range[3]) ];
2022-12-13 09:20:36 +01:00
2023-10-29 06:29:10 +01:00
var _dest = getInputData(effector_input_length + 2);
2023-10-10 07:12:42 +02:00
var pv = part.getPivot();
2022-12-13 09:20:36 +01:00
var dirr = point_direction(pv[0], pv[1], _area_x, _area_y);
2023-10-10 07:12:42 +02:00
part.x = part.x + lengthdir_x(_sten * str, dirr);
part.y = part.y + lengthdir_y(_sten * str, dirr);
2022-12-13 09:20:36 +01:00
part.rot += _rot * str;
var scx_s = _sca[0] * str;
var scy_s = _sca[1] * str;
2023-01-17 08:11:55 +01:00
if(scx_s < 0) part.sc_sx = lerp_linear(part.sc_sx, 0, abs(scx_s));
else part.sc_sx += sign(part.sc_sx) * scx_s;
if(scy_s < 0) part.sc_sy = lerp_linear(part.sc_sy, 0, abs(scy_s));
else part.sc_sy += sign(part.sc_sy) * scy_s;
2023-10-29 06:29:10 +01:00
if(_dest && point_distance(part.x, part.y, _area_x, _area_y) <= _sten)
part.kill();
2022-12-13 09:20:36 +01:00
}
}