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

GameMaker Gun keeps firing

ChrisC

Member
I just moved to GMS2 from 1, I basically started my project over and was trying to pull code from my old game to my new one. the code works perfectly fine in 1 but it just keeps shooting after my first button press now in GMS2

GML:
nearestOpponent = instance_nearest(x,y + z, oHoming)

if (kShoot and onGround)         // If shoot button and touching ground..
and distance_to_object(nearestOpponent) < gunrange
and (state = RUN or state = IDLE)
{
if nearestOpponent.x > x
{
facing = RIGHT
}
else
{
facing = LEFT
}
if startammo <=0
{
hit = true;  //hit only true to keep player from moving.
state=NOAMMO;
alarm[0] = 5;
}
else
{

if !hit         // If Player got a kHit1 input and the hit flag is false...
{
    //audio_play_sound(sGunshot, 0, false);
    startammo -=1;
    hit = true;             // ...makes a hit (hit flag to true)
    shot = instance_create_depth(nearestOpponent.x,nearestOpponent.y,depth,oHitCollisionGunLegacy);    // Create the punch Hit box
    shot.depth = depth + 1;
    shot.parentId = id;    // and store the Player instance id in de Hit box instance to know who made that hit
    image_index = 0;    // Reset the animation for every hit
    state = SHOOT;    // Go to SHOOT state
    shot.damage = gundamage;   // Determines the damage that the hit box will make to enemies
    alarm[0] = 5;      // Can't hit again until alarm is finished
}}}
 

Nidoking

Member
There's probably something you're supposed to reset when you shoot that you're not doing. That's all that's likely to be said about what you've posted here.
 
Top