• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Collision line [Solved]

P

PatatjeFriet

Guest
Hello,

So i am working on a game at which the unit shoots at the point an enemy is in its shooting range. I have an animation for when he is supposed to shoot and with reload in one. But when i test it the unit will do the animation for the amount of the first alarm but then restarts the animation again at which i get a loop and the reload animation won't come.

Thanks in advance

Code:
Create:
Code:
//variables
attack = 0;
attackmove = 0;
ready = 1;
//health
hp = 60;
hb = (hp/60)*100;
Step:
Code:
//move
if !position_meeting(self.x+16,self.y+14,obj_unit) && !attack = 1 && !position_meeting(self.x+16,self.y+14,obj_toren_enemy){
    hspeed = 1;
}
else {
    hspeed = 0;
}
//attack
if collision_line(self.x,self.y+14,self.x+128,self.y+14,obj_enemy,true,false) {
    attack = 1;
}
else {
    attack = 0;
}

if attack = 1 {
    if ready = 1 {
        attackmove = 1;
        alarm[0] = 12;
        ready = 0;
    }
}
//damage
if place_meeting(x,y,obj_pike_enemy) {
    hp -= 10;
}
//health
hb = (hp/60)*100;
if hp <= 0 {
    instance_change(obj_pikeman_death_left,false);
}
Alarm[0]:
Code:
//create bullet
if attack = 1 {
    instance_create(self.x,self.y,obj_pike);
    alarm[1] = 60;
}
Alarm[1]:
Code:
//reload done
attackmove = 0;
ready = 1;
Draw:
Code:
//draw
//standing still
if hspeed = 0 && !attackmove = 1 {
    draw_sprite(spr_musketeer_idle_left,0,self.x,self.y);
}
//moving
if hspeed > 0 {
    draw_sprite(spr_musketeer_walk_left,image_index,self.x,self.y);
}
//attack
if attackmove = 1 && !hspeed > 0{
    draw_sprite(spr_musketeer_attack_left,image_index,self.x,self.y);
}
//health
draw_healthbar(self.x-8,self.y-11,self.x+8,self.y-10,hb,c_black,c_red,c_green,0,true,false);
 

curato

Member
I think your logic is a bit muddled with the attack and attackmove maybe the reload should have attack = 0; as well.
 
P

PatatjeFriet

Guest
Could you explain a little bit further i am not that experienced with game maker. I tried seperating the shooting and reloading but they both have the same problem as before they do it for like 1 sec and then reloop while the animation in total is 3 sec.
 

curato

Member
if they are all looping when it isn't expected you could use the animation end even to look at which animation is running and stop it or replace it with other animation if you only want it to play once.
 
P

PatatjeFriet

Guest
I think i found the problem but don't know how to fix it. I tried the animaiton it self if it would play the whole way but it seems the animation just stops after a few frames and which it restarts. The problem isn't in the part of the code i thought it was. Is in gamemaker something which sets the amount of frames a image can have. My image has 72 frames but just shows a few in the beginning. I use image_index at what i thought would do all the frames but appeariantly doesn't

EDIT:
Found the solution. I had as spr image a image with 19 frames at that prohibited my 72 frame animation to go past 19 frames. Thanks for the help.
 
Top