T
Tyson Boyer
Guest
I noticed someone posted something very similar to this a day ago, but not quite the same since I have the orbiting part coded. Was not sure if it would be better to piggyback that thread or create my own so hope I made the right decision. Anyways, onto the question.
I want my enemy to strafe around the player, which I have pretty much got it to do, but the enemy object will, usually, but not always, jump to another location once and then begin to strafe. I think it is happening because the enemies x and y are changing between state transitions, but I am not sure. This is what it looks like.
This is the alert state that creates a path for the enemy to follow to the player and when the enemy is close enough it will enter the attack state.
Here is the attack state.
And here is the relevant information from the enemy create event.
I want my enemy to strafe around the player, which I have pretty much got it to do, but the enemy object will, usually, but not always, jump to another location once and then begin to strafe. I think it is happening because the enemies x and y are changing between state transitions, but I am not sure. This is what it looks like.
This is the alert state that creates a path for the enemy to follow to the player and when the enemy is close enough it will enter the attack state.
Code:
if (instance_exists(o_player) && collision_circle(x, y, alert_radius, o_player, false, false)) {
show_debug_message("ALERT");
mp_grid_path(global.enemy_pathing_grid, global.enemy_path, x, y, o_player.x, o_player.y, true);
path_start(global.enemy_path, alert_spd, path_action_stop, false);
if (collision_circle(x, y, fight_radius, o_player, false, false)) {
show_debug_message("FIGHT");
path_clear_points(global.enemy_path);
current_state = STATE_ENEMY.ATTACK;
previous_state = STATE_ENEMY.ALERT;
} else {
current_state = STATE_ENEMY.ALERT;
}
} else {
show_debug_message("EXIT ALERT");
path_clear_points(global.enemy_path);
current_state = STATE_ENEMY.IDLE;
}
Code:
if (instance_exists(o_player) && collision_circle(x, y, fight_radius, o_player, false, false)) {
show_debug_message("STRAFE");
orbit_angle += orbit_speed;
orbit_length = point_distance(orbit_target.x, orbit_target.y, x, y);
x = orbit_target.x + lengthdir_x(orbit_length, orbit_angle);
y = orbit_target.y + lengthdir_y(orbit_length, orbit_angle);
} else {
show_debug_message("EXIT STRAFE");
current_state = STATE_ENEMY.ALERT;
}
Code:
alert_radius = 128;
alert_spd = 1.5;
attacking = noone;
fight_radius = 64;
attack_radius = 24;
attack_count = 0;
orbit_target = o_player;
orbit_speed = 1;
orbit_length = point_distance(orbit_target.x, orbit_target.y, x, y);
//orbit_angle = point_direction(x, y, orbit_target.x, orbit_target.y);
orbit_angle = 0;