When the enemy move's to the right their gun faces right. When they move left the gun will face left as it should. When the player collides with the enemy collision line on the right side, the enemy gun will point towards the player properly.
When the player is on the left side of the enemy and hits the collision line, the enemy gun will sort of point towards the player but not facing the right direction.
Step Event of Enemy gun object:
//image_xscale = 1 is looking to the right, -1 is left
// I use image_angle so the enemy gun will aim at the player on x and y axis
if obj_testEnemy.image_xscale == 1 { //When the enemy is looking to the right
if (collision_line(x, y, x + 128, obj_testPlayer.y , obj_testPlayer, false, true)) {
image_angle = point_direction(x,y,obj_testPlayer.x,obj_testPlayer.y); //how it aims at the player
} else {
image_angle = obj_testEnemy.image_xscale; // faces the correct direction when not colliding
}
} else {
if (collision_line(x, y, x - 128, obj_testPlayer.y , obj_testPlayer, false, true)) {
image_angle = point_direction(x,y,obj_testPlayer.x,obj_testPlayer.y);
image_xscale = -1; //gun should be facing left but it's not
}
}
I don't understand why the gun won't face left when the collision line is facing left
Working:
Not Working: