GMS 2.3+ check collision between a parent object and different children

Stratos.la

Member
so i have a parent enemy and a parent obstacle. there is a collision happening that makes the enemies stop and go into attack animation. it works great with the first object that has the same values as the parent but the rest i dont know how to check them.
WIth details now . i have a barricade object that when spawned the enemies stop and attack it for 5 seconds. in the barricade object collision event i have this
GML:
with other{
if distance_to_object(oBarricade) <= 1
    {
        spd = 0;
        sprite_index = oEnemyParent.attack
        image_speed = 0.6
    }
}
and when it gets destroyed i want to set tha animation back to the walk one and the speed to the speed of each object.

GML:
with other
{
    spd = 2; // it should be if enemy == 1 spd = 2 else if else if but i dont want to do it like this!
    sprite_index = other.walk // and here it should see which object it was and continue with its walk animation
    image_speed = 1
}
Now i have one EnemyParent object that has all of the code for animations, behaviors etc and all of the create event is inside variable definitions which i change for all 3 enemies that are its children. So if enemy1 has 3 speed and enemy 2 has 5 speed how can i check with which instance the barricade has collided with so it sets its speed back to the correct value?
I know i should put the collition in the enemy parent but im just testing things now . i do want to make a parent obstacle object so maybe that is the answer?

this is the enemy parent step event . the actuall object doenst have a create event
GML:
if (instance_exists(oPlayer))
{   
    x -= spd*global.spdScale
    sprite_index = walk // this is defined as a sprite in the variable definitions of each child
        if (global.spdScale > spdSlow)
        {image_speed = 1;}
        else
        {image_speed = 0.1;}
}

///attack

if distance_to_object(oPlayer) < 1
{
    spd = 0;
    sprite_index = attack // this is defined as a sprite in the variable definitions of each child
    image_speed = 0.9
}

///die

if hp <= 0
{
    
    spd = 0;
    image_speed = 0.9
    if image_speed > 0
    {
    if image_index > image_number - 1 instance_destroy();   
    instance_destroy();
    instance_create_depth(x,y,200,DeathObject) // this is defined as a sprite in the variable definitions of each child
    }   
}
 

Nidoking

Member
GML:
with other
{
spd = 2; // it should be if enemy == 1 spd = 2 else if else if but i dont want to do it like this!
sprite_index = other.walk // and here it should see which object it was and continue with its walk animation
image_speed = 1
}
What event is this in? You said this is when it's destroyed, but is it in a Collision event? If not, then what value do you think other has? It may just not be defined in this context at all.
 

Stratos.la

Member
this is inside the barricade objecr destroy event. the barricade is active for 5 seconds through an alarm. in that time if enemies get close they stop and go into attack animation. when the time is over they should start moving again towards their point to go. the Enemy parent object has all those variables stored in the variable definitio tab, like spd, sprites , health etc. each child now uses the same step event,draw event, destroy event etc but they have different sprites and variables like spd , hp and so on
 

Nidoking

Member
In the object destroy event, you can't use "other" the way you appear to be. You need to figure out which enemy instances you want to handle and access them that way.
 
Top