How do I link two different objects together?

0 favourites
  • 6 posts
From the Asset Store
Adjusting the game screen for different resolutions (Letterbox scale)
  • Hey,

    This is what I'm trying to do:

    I'm spawning an ennemy which is composed by an invisible sprite with platform behavior and alongside with it an animation with collision detection that is pinned to the invisible sprite. I want to do some events like:

    When Animation is hit by a weapon

    Set Animation to play some animation

    Set InvisibleSprite to stop moving for 1 second

    But of course this applies to every invisible sprites. I tried to make an instance variable that is stocking the UID of the other sprite and pick it in my event but I can't get this working. Someone could give me a lead?

  • Try doing if weapon collide sub event everything you want it should only apply to the one that got hit not all.

  • Try doing if weapon collide sub event everything you want it should only apply to the one that got hit not all.

    I don't know If I get what you mean but would that change anything ? I think my problem is action-sided. Like, for my weapon, my event includes the collision with the animation, but the action includes the animation AND the invisible sprite. I would need either an event for telling "pick this specific instance and this specific instance" or an action in another event that would tell "this instance needs to do this at the same time that that instance".

  • Add a number variable called "Parent" to the pinned invisible sprite and one called "ID" to the visible Animation sprite. Set the Parent value to be the same as the ID of the Animation sprite, make sure every visible Animation sprite has a unique ID and the pinned invisible sprites are assigned the correct parent IDs.

    Under the "Animation hit by Weapon" condition, add a second condition "Compare instance variable [Parent] for Invisible Sprite", with the value of parent equal to "Animation.ID" (the ID number of the hit animation will be retrieved by construct). That way the hit by weapon event will pick only the invisible sprite that has the right animation designated as a parent, and any actions you add in the same event will apply only to that invisible sprite.

    I think this can also be done with containers but I got used to doing it as above that I never bothered with containers.

  • Thank you, it seems to be a good way. Still I'm missing something. I've simplified my example but in fact I've got two objects on the two sides, like:

    Animation hit by weapon and InvisibleSprite is on floor

    Set Animation "hit" and InvisibleSprite to stop for 1 second

    I tried to compare values on both objects but the results are weird, like when the first animation is hit the second is stopping (the values are correct, I've checked).

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Well, I have absolutely no idea why, but as soon as I put "For each"in my events, everything worked like a charm. For now I'm going to hope that it doesn't bring weird bugs later.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)