Hitting opponents, not me, but same object.

Discussion in 'Programming' started by DiamondCraft, Mar 14, 2019 at 6:57 PM.

  1. DiamondCraft

    DiamondCraft Member

    Joined:
    Wednesday
    Posts:
    5
    So im making a smash bros-ish game where you can have the same character but i dont want the onjects spawned that are used as projectiles, not the melee attacks, to hit the object (the player) that used the move to do the attack. i want to spawn the projectile on top of the original character and im doing this in Drag and Drop. Any suggestions? Thanks for the help.
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    1,572
    In other words you want to create an instance of object B with an instance of object A, and you want object B to be able to damage all instances of object A except for the one that created it?

    Code:
    
    ///in object A
    var object_b = instance_create...
    with (object_b) {
        owner = other.id;
    }
    
    ///in object B
    with (object_a) {
        if (id != other.owner) {
            ///check for collision/damage etc
        }
    }
    
    
    Obviously, the above code isn't going to work exactly like that in your game, but the idea will. Save the instance id of the creating object as a variable in the created object and when doing collision checks, check the instance id against the saved variable before doing damage.

    If that doesn't make sense the following might be helpful:
     

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