Roastedzerg
Member
Hey guys, I'm having trouble trying to rack my brain on this. Basically im creating an isometric 2d top down game and am working on giving the illusion of flight by raising the sprite of the flying objects above their real location but subtracting sprite_height from their Y to bring them up and stretching their image_xscale and image_yscale by adding sprite_stretch, all on their draw event like so:
The enemy objects all work like a charm, however, right now I'm trying to make them shoot projectiles down at the player, and its not fairing so well. Basically, I'm having trouble getting them to decrease sprite_fly when the target is closer, making the projectile look like its dropping slower, and faster when the target is further away. I'm thinking this should give a good illusion of the projectile shooting down from higher up. I feel like I got close, but right now the formula I tried does the opposite and moves faster when the player is close and slower when they are far. Here's what I'm using:
I'm not so great at math so for the most part i just kind of fudged it, maybe you guys can guide me on where im going wrong here. This is hard to explain, but let me know if you need any more details.
Thank you
EDIT 1: To clearify its not so much the movement to the player that is the problem, its dropping the sprite y axis using sprite_fly that is giving me issues. specifically changing the speed of the drop to be slower when target is close and faster when the target is further away.
Edit 2: For some reason when the player is standing where the enemy shadow is (the actual location of the enemy object) the bullet doesnt shoot correctly and instead is shot from below the shadow or created directly on the player. This probably has to do with the fact that the bullet is technically being created from the object (shadow) and then the sprite is using sprite_fly to make it appear to be higher up. So when the player stands near the shadow the bullet only moves a few pixels out, possibly causing this glitch.
Edit 3: if it helps, here is the code used in the enemies shoot while flying state when creating a bullet:
GML:
draw_sprite_ext(sprite_index,image_index,x,y-sprite_fly,image_xscale+sprite_stretch,image_yscale+sprite_stretch,image_angle,image_blend,image_alpha);
GML:
//Movement
distance=point_distance(x,y,fly_shoot_x,fly_shoot_y);
if(round(distance)>5)
{
speed=fly_projectile_speed;
move_towards_point(fly_shoot_x,fly_shoot_y,speed);
}
else{speed=0;}
//Falling
if(start_fall)
{
start_fall=false;
sprite_fly_start=sprite_fly;
fall_time=distance*(1/fly_projectile_speed);
fall_speed=sprite_fly_start/fall_time;
}
if(sprite_fly>0){sprite_fly-=fall_speed;}else{sprite_fly=0;}
if(sprite_stretch>0){sprite_stretch-=sz;}else{sprite_stretch=0;}
if(image_alpha<1){image_alpha+=al;}else{image_alpha=1;}
Thank you
EDIT 1: To clearify its not so much the movement to the player that is the problem, its dropping the sprite y axis using sprite_fly that is giving me issues. specifically changing the speed of the drop to be slower when target is close and faster when the target is further away.
Edit 2: For some reason when the player is standing where the enemy shadow is (the actual location of the enemy object) the bullet doesnt shoot correctly and instead is shot from below the shadow or created directly on the player. This probably has to do with the fact that the bullet is technically being created from the object (shadow) and then the sprite is using sprite_fly to make it appear to be higher up. So when the player stands near the shadow the bullet only moves a few pixels out, possibly causing this glitch.
Edit 3: if it helps, here is the code used in the enemies shoot while flying state when creating a bullet:
GML:
my_fly_bullet=instance_create_depth(x,y-my_height,depth,fly_bullet_type)
my_fly_bullet.my_parent=self.id;my_fly_bullet.direction=aim_dir;
my_fly_bullet.fly_projectile_speed=fly_projectile_speed;
my_fly_bullet.fly_shoot_x=fly_shoot_x;my_fly_bullet.fly_shoot_y=fly_shoot_y;my_fly_bullet.fly_shoot_distance=fly_shoot_distance;
my_fly_bullet.sprite_fly=sprite_fly;my_fly_bullet.sprite_stretch=sprite_stretch;
Last edited: