How do I link two different objects together?

Get help using Construct 2

Post » Fri Aug 19, 2016 6:27 pm

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?
B
15
S
7
G
2
Posts: 18
Reputation: 2,165

Post » Fri Aug 19, 2016 6:44 pm

Try doing if weapon collide sub event everything you want it should only apply to the one that got hit not all.
B
52
S
24
G
6
Posts: 391
Reputation: 7,845

Post » Fri Aug 19, 2016 7:06 pm

Gearworkdragon wrote: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".
B
15
S
7
G
2
Posts: 18
Reputation: 2,165

Post » Fri Aug 19, 2016 7:26 pm

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.
B
15
S
6
Posts: 85
Reputation: 1,195

Post » Fri Aug 19, 2016 8:09 pm

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).
B
15
S
7
G
2
Posts: 18
Reputation: 2,165

Post » Sat Aug 20, 2016 6:03 am

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.
B
15
S
7
G
2
Posts: 18
Reputation: 2,165


Return to How do I....?

Who is online

Users browsing this forum: Elliott, kellehk, oosyrag, totoe and 23 guests