• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

SOLVED Get center of every children of Parent_Enemy instance

Axl Trauts

Member
Hi,

I have a top down shooter and I have this special gun that shoots sticky bombs from above. The should appear at the middle of every enemy instance using its parent par_Enemy.
Each enemy has different origins due to their unique behaviors, so using something like this on the script that fires the sticky bomb, it won't appear on the center of every instance but the ones with 0,0:

GML:
    if !instance_exists(obj_stickybomb)
    {    with(par_Enemy)
        {    if enemy_type="ALL"    // not relevant now
            {    instance_create_depth(x+sprite_width/2,y+sprite_height/2,par_Enemy.depth-1,obj_stickybomb);
            }
        }
    }
I don't want to modify permanently all their origins with sprite_set_offset. If there's no way, I'll have to figure out a different effect.
 

TheouAegis

Member
bbox_left+bbox_right>>1
And
bbox_top+bbox_bottom>>1

That's for center of bounding box.

Otherwise you will need to subtract sprite_xoffset and sprite_yoffset from x and y then add half-width and half-height.
 
Top