T
TheCount15
Guest
I have some code below for a simple ally Ai. However I am not sure how to have the ally drone skip the top code if there are no enemies nearby. If I use if(!instance_exists(obj_Player)) exit; then the ally will just float off brain dead. Very new to coding and not sure what to do here.
---------------------------------------------------------------------------------------------------------------------------
Ally Drone step:
if (point_distance(x,y, obj_Par_Enemy.x, obj_Par_Enemy.y) < 500){
follow_character(obj_Par_Enemy, 400, 300);
shoot_target("lazer", obj_Par_Enemy, 30, faction, 400);
}
else{
if(!instance_exists(obj_Player)) exit;
follow_character(obj_Player, 10000, 100);
}
--------------------------------------------------------------------------------------------------------------------------
follow_character script:
// Script assets have changed for v2.3.0 see
// https://help.yoyogames.com/hc/en-us/articles/360005277377 for more information
function follow_character(_character, _distance, _distanceStop){
var char = _character;
var dst = _distance;
var dsts = _distanceStop;
if(!instance_exists(char)) exit;
if(point_distance(x,y, char.x, char.y) <dst){
// Turn to look at player
var new_angle = point_direction(x,y, char.x, char.y);
new_angle = image_angle - angle_difference(image_angle, new_angle);
image_angle = lerp(image_angle, new_angle, 0.1);
direction = image_angle;
speed +=0.01;
// Clamp speed to maximum
speed = min (speed, 2)
if(point_distance(x,y, char.x, char.y) <dsts){
speed -= 0.02;
} else {
speed += 0.01;
}
} else {// otherwise, no change
image_angle = lerp(image_angle, direction, 0.1);
speed = lerp(speed,originalSpeed, 0.1);
}
}
--------------------------------------------------------------------------------------------------------------------
Shoot_target script:
// Script assets have changed for v2.3.0 see
// https://help.yoyogames.com/hc/en-us/articles/360005277377 for more information
function shoot_target(_weapon, _target, _speed, _faction, _distance){
var wp = _weapon;
var tgt = _target;
var spd = _speed;
var faction = _faction;
var dst = _distance
if(!instance_exists(tgt)) exit;
if(point_distance(x,y, tgt.x, tgt.y) <dst){
// Turn to look at player
var new_angle = point_direction(x,y, tgt.x, tgt.y);
new_angle = image_angle - angle_difference(image_angle, new_angle);
image_angle = lerp(image_angle, new_angle, 0.1);
direction = image_angle;
}
if _weapon = "lazer"
{
if(point_distance(x,y, tgt.x, tgt.y) <dst){
bulletCounter++;
if (bulletCounter >=40){
wp = create_Lazer(image_angle, spd, faction);
bulletCounter = 0;
}
}
}
}
---------------------------------------------------------------------------------------------------------------------------
Ally Drone step:
if (point_distance(x,y, obj_Par_Enemy.x, obj_Par_Enemy.y) < 500){
follow_character(obj_Par_Enemy, 400, 300);
shoot_target("lazer", obj_Par_Enemy, 30, faction, 400);
}
else{
if(!instance_exists(obj_Player)) exit;
follow_character(obj_Player, 10000, 100);
}
--------------------------------------------------------------------------------------------------------------------------
follow_character script:
// Script assets have changed for v2.3.0 see
// https://help.yoyogames.com/hc/en-us/articles/360005277377 for more information
function follow_character(_character, _distance, _distanceStop){
var char = _character;
var dst = _distance;
var dsts = _distanceStop;
if(!instance_exists(char)) exit;
if(point_distance(x,y, char.x, char.y) <dst){
// Turn to look at player
var new_angle = point_direction(x,y, char.x, char.y);
new_angle = image_angle - angle_difference(image_angle, new_angle);
image_angle = lerp(image_angle, new_angle, 0.1);
direction = image_angle;
speed +=0.01;
// Clamp speed to maximum
speed = min (speed, 2)
if(point_distance(x,y, char.x, char.y) <dsts){
speed -= 0.02;
} else {
speed += 0.01;
}
} else {// otherwise, no change
image_angle = lerp(image_angle, direction, 0.1);
speed = lerp(speed,originalSpeed, 0.1);
}
}
--------------------------------------------------------------------------------------------------------------------
Shoot_target script:
// Script assets have changed for v2.3.0 see
// https://help.yoyogames.com/hc/en-us/articles/360005277377 for more information
function shoot_target(_weapon, _target, _speed, _faction, _distance){
var wp = _weapon;
var tgt = _target;
var spd = _speed;
var faction = _faction;
var dst = _distance
if(!instance_exists(tgt)) exit;
if(point_distance(x,y, tgt.x, tgt.y) <dst){
// Turn to look at player
var new_angle = point_direction(x,y, tgt.x, tgt.y);
new_angle = image_angle - angle_difference(image_angle, new_angle);
image_angle = lerp(image_angle, new_angle, 0.1);
direction = image_angle;
}
if _weapon = "lazer"
{
if(point_distance(x,y, tgt.x, tgt.y) <dst){
bulletCounter++;
if (bulletCounter >=40){
wp = create_Lazer(image_angle, spd, faction);
bulletCounter = 0;
}
}
}
}
Attachments
-
11.9 KB Views: 5