1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Child object not registering hit

Discussion in 'Programming' started by Disgolaxe, Feb 2, 2018.

  1. Disgolaxe

    Disgolaxe Member

    Joined:
    Mar 25, 2017
    Posts:
    4
    The projectile I have named "contact" has this in it.

    if instance_place(x,y,Actor) and Actor.hit {
    Actor.HP -= 1;
    instance_destroy()
    }
    else
    if instance_place(x,y,Actor) and Actor.blockhit {
    Actor.HP -= 1 - Actor.block;
    instance_destroy()
    }

    "Actor" is the parent object.
    "Enemy" is the child object.

    I must be missing something crucial about how the parent-child function works in GML, because when I shoot at Enemy it doesn't register the collision with the projectile, whereas if I shoot the parent object it works as intended. Any advice as to why this is?
     
  2. JFitch

    JFitch Member

    Joined:
    Sep 28, 2016
    Posts:
    428
    object.variable does not work with parents, and it's only recommended if you have exactly one instance of that object.
     
    Disgolaxe likes this.
  3. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,707
    What you're actually missing is the difference between an object and an instance.

    Combining both points:
    Code:
    var colliding_actor = instance_place(x, y, Actor);
    if (colliding_actor != noone) {
      if (colliding_actor.hit) {
        colliding_actor.HP -= 1;
        instance_destroy();
      } else if (colliding_actor.blockhit) {
        colliding_actor.HP -= 1 - colliding_actor.block;
        instance_destroy();
      }
    }
    
     
    Disgolaxe likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice