• 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!

Hitbox Doesn't Spawn

D

discocar

Guest
///Kick
//Make sure we are attacking
if(state = "attacking"){
sprite_index = spr_AIKick //Set the sprite animation
image_index = 0 //Make sure we start the animation from the begining
///hitbox

}
if (image_index==4)
{
with (instance_create (x,y,oKickHitbox)) //Create hitbox
{
image_xscale = other.image_xscale; //Create the hitbox in the right direction
}
}

I set it so it should spawn when it hits the frame index 4 and It isn't in the same code above its outside it. I don't understand why its not spawning it? haha Any help would be great. Thanks
 

Kahrabaa

Member
Code:
if ( floor( image_index ) ==4)
Try this because its possible that your image_speed is in decimals. So for example if image_index increases in steps of 0.3 then 3.3 -> 3.6 -> 3.9 -> 4.2 Never actually becoming exactly 4. So you use floor.
 
D

discocar

Guest
hmm still doesn't appear, kinda weird. When I remove the Image_index code it appears. But appears at the beginning of the animation. and randomly appears when hes moving around haha.
 

Kahrabaa

Member
You have a line that says
image_index = 0 //Make sure we start the animation from the begining
This resets the index to 0 constantly not allowing it to increase. So do you change state to something other than "attacking"? Does the kicking animation even play?

Btw. How many frames does the animation have?
 
Last edited:
D

discocar

Guest
the Animation has 4 frames, with the attack on the 4th frame.

The kicking animation does play. Just no hitbox.

yeah there are various states, moving back and forth and punching and kicking.
 

Relic

Member
As with many aspects of programming, the first animation frame is 0, not 1. So you want to try spawning the hitbox when the image index is 3, the last frame. You should still keep the floor() to assist with non integer values
 
D

discocar

Guest
I tried a bunch of stuff, still doesn't appear. I have no idea why. This is what the code looks like now.

///Kick
//Make sure we are attacking
if(state = "attacking"){
sprite_index = spr_AIKick //Set the sprite animation
//Make sure we start the animation from the begining
///hitbox



if (image_index=4)
{
with (instance_create (x,y,oHitboxKick)) //Create hitbox
{
image_xscale = other.image_xscale; //Create the hitbox in the right direction
}
}
}

and I have actually five frames.

I was wondering, would it be possible to just use the built in the collision. So when they collide they hurt. but only have them hurt when an attack animation is happening and only have it hurt for a certain amount of time? if that makes sense
 

Rob

Member
What the issue might be is that image_index isn't always a whole number. It could be 3.5 or 3.7. It's down to the image_speed you set. Double check this isn't the issue by using

Code:
[Draw event of player]

draw_set_halign(fa_left);
draw_set_valign(fa_top);
draw_set_colour(c_white);

draw_text(0, 0, string(image_index));
You can use the built in collision but you have more control over it by doing it yourself.
 
Top