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

Hitboxes and Position of Objects

I programmed a hurt box for my enemy and it is working perfectly. I have it so that when the enemy gets destroyed, the hitbox gets destroyed with. When I have 2 enemies in the room and when I destroy one enemy, all of the hitboxes get destroyed. What I want to happen is when a specific enemy gets destroyed, the hitbox that is associated with that enemy gets destroyed.

This is in the destroy event
GML:
with(other)
{
instance_destroy(obj_hurtbox)
}
Also, another issue I have is when I attack an enemy, he will always go to the right when attacked. I am trying to program it so that he is going in the direction that he is getting attack from.

Create
GML:
facing = 1
In Step

GML:
//Flipping Sprites
if (dir != 0) image_xscale = sign(dir);
In End Step

GML:
//get hit
if(hit){
  
    hsp = hitBy.xHit;
    hitStun = hitBy.hitStun;
    facing = hitBy.owner.facing * -1;
    hp -= hitBy.damage
    hit = false;
    sprite_index = spr_grunthit;
    grunt = grunt.hurt;
}
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
What I want to happen is when a specific enemy gets destroyed, the hitbox that is associated with that enemy gets destroyed.
For that you need to store the ID of the hitbox instance in a variable, then use THAT in the instance destroy command instead of the general hitbox object index (as you are doing now). For example:
GML:
// CREATE EVENT OF ENEMY OBJECT
hitbox = instance_create_layer(x, y, layer, obj_hurtbox);

// DESTROY EVENT OF ENEMY OBJECT
instance_destroy(hitbox);
 
For that you need to store the ID of the hitbox instance in a variable, then use THAT in the instance destroy command instead of the general hitbox object index (as you are doing now). For example:
GML:
// CREATE EVENT OF ENEMY OBJECT
hitbox = instance_create_layer(x, y, layer, obj_hurtbox);

// DESTROY EVENT OF ENEMY OBJECT
instance_destroy(hitbox);

I got it to work, it was a bit different because i forgot I had a script for it and I used it but thank you for getting me into the right direction. The only issue I have now is the positioning when the enemy gets attacked by the player. I been trying to figure that out for days now.
 
Top