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

Legacy GM Quick problem with HP

V

VicoZann

Guest
So I'm setting up the damage and destruction functions for the enemies in my game, starting with the all powerful metal box. I want to kill this box. And I can kill the box. But that's the problem.

if(place_meeting(x,y,parent_hitbox))
{
hp -= parent_hitbox.damage;
}


if(hp <= 0)
{
instance_destroy();
}

I attack, generate the hitbox, it touches the box and the box takes damage and dies. But the damage doesn't stop reducing it's HP until the box dies. If I hit it with the punniest attack ever, it will still drain it's HP until it's destroyed.

The hitbox for the attacks only lasts 1 frame, but I suppose that there's nothing coded telling the hp -= code to stop reducing the HP. I'm just not sure how exactly I show go about to fixing this

I searched for tutorials online, namely Heartbeast's and Shaun Spalding's but both of them, as far as I understood, arranged the damaging script in a similar way to mine, so, why doesn't the damage stops damaging after the hitbox disapears?


=============================
Edit
============================
With more testing, I noticed yet another problem. I have a parent hitbox object that is the one responsible for destroying the hitboxes and many other child hitboxes each with their own damage and shape, for different attacks. But for some reason the first attack I use in a room will make every other hitbox have the same damage, so if I use a strong attack and then a weak one, the weak will do the same damage as the strong
 
Last edited by a moderator:
T

Tom Foster

Guest
does the damaging object destroy itself after it has hit the box?
alternatively if it cannot be destroyed set its damage to 0 untill the action to let it damage somthing is called again
 
V

VicoZann

Guest
It has a Post Draw event that destroys it, so it only existis for a single frame. I tried using a collision event instead of a step event for the damaging of the box, since that's what heartbeast did, but it's still draining the hp
 
V

VicoZann

Guest
No. The hitbox is created for usually 2 to 3 frames, variates acording to the attack being used. This would mean that the attack would hit that same amount of times, but for testing purposes I made the box have a ton of HP just to be sure so that's not the problem
 
V

VicoZann

Guest
I added a jumping effect to the attack hit, so that whenever I hit the box, it should do a little jump. What happneded was that the box began jumping non stop until destroyed. This make it seens that the collision effect could still be triggered, but...why?
 

TheouAegis

Member
Are you sure only 1 parent_hitbox is in the room? You aren't referencing the hitbox that actually collided with the enemy.
 
V

VicoZann

Guest
Are you sure only 1 parent_hitbox is in the room? You aren't referencing the hitbox that actually collided with the enemy.
Honestly I'm never sure about anything ever, but the way I tried to make things work is by referencing only the parent hitbox, that never actually exists and isn't really a hitbox, is just a parent object with the generic codes that all other hitbox gets. The actual call for a hitbox happens in the attack script.

Now, I'd like to believe that the hitboxes are appearing and disapearing correctly, since if I toogle their visibility on they show up and are destroyed as expected. Only that for some reason when they are visible they don't work for some reason. As long as a hitbox is visible, the contact with the box won't trigger any effect and I have no clue why this happens
 
V

VicoZann

Guest
For testing reasons, I killed all but a single hitbox so I could focus on making at least that one work before moving on to the others and, surprise, I'm still having the exact same problems. The hitbox only works if it's invisible, the HP of the enemy is being drained until it's destroyed and I'm completely lost.
Help please, I'm getting desperate here
 
A

Azure Spectre

Guest
What does your hitbox code look like? The hitbox is almost definitely not destroying itself.

A quick solution would be to modify your above code like so:
Code:
if(place_meeting(x,y,parent_hitbox))
{
    var ii=instance_nearest(x,y,parent_hitbox);
    hp -= ii.damage;
    with(ii)
    {
        instance_destroy();
    }
}
But that comes with it's own set of problems if you have multiple enemies you need to hit with one attack , or lots of different sized hitboxes.
 
Top