Enemy actors swinging weapons on player collision


  • Posts: 649

I'm very new to Stencyl.

I am trying to set up 2 enemy actors (Knights) that chase the player using 'Follow Target' behaviour.  When they collide, I want another actor, Sword, to be created and to play the animation of it swinging.

To achieve this, the best I have managed is when the enemy actor is created, to also create the Sword actor under an idle animation placed upon the x,y of the Enemy.  This sword then follows the enemy actor around screen.

The problem I am having is the actions of the created Sword actors all activate in unison, if 1 swings upon collision with the player they all do.  Also, because they are linked to the Enemy Actors created and following 'Last Created Actor' only 1 Sword tracks their respective Enemy Actor, the other stays still.

Ideally, I want to create a scene with multiple Knights that chase the player around screen, upon collision they swing a sword (Not to be shown til this point), when there is no collision, there is no Sword.  I'm trying to do it this way to learn so I can have various Actors / Player picking up new weapons along the way without redoing lots of Artwork i.e Zelda Dilemma.



  • *
  • Posts: 430
I believe that Last Created Actor returns the last actor created throughout the entire scene. Maybe you could set an actor attribute to Last Created Actor immediately after the sword is created, then use that attribute in place of Last Created Actor.
Fontstruct - Stencyl - Website (in progress)

Proud Member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.


  • Posts: 257
Create an actor attribute for sword and use as many as you need. Drag these attributes to the create blocks.


  • Posts: 649
Thanks, that makes sense.

I have created a new Actor Type Attribute - 'Knight_Sword_Type' and chosen the Actor Type of Sword as it's default value, and selected this through 'Create' instance, that works.

Though I'm getting unstuck with the Actor Attribute for making them follow the Kinght.  I have also created the Actor Attribute, 'Knight_Sword_Ind', but I don't know how to link it to any particular actor.  I have selected it as a replacement for 'set x to x for 'last created actor',  but at the moment I think it is just an empty attribute not linked to anything as it's crashing the  game?  How do I link this to my newly created Actor Type?


  • Posts: 649
Fantastic!! Thank you very much for your help!

I created an Actor Attribute - 'Each_Sword', then once the 'Create Sword_Type' instance was run, set the 'Each_Sword' attribute to 'Last Created Actor.

Then used that 'Each_Sword' Actor Attribute in setting the x,y of it in accordance with the Knights.

I've now edited the code slightly as I want to only create the Sword upon collision, and not when the Knights were created, how would I do this?    I'm guessing I need some kind of blocker in place to only create one instance?  So I have created that in the image below, but this is not playing the full loop animation of the sword swinging- it's just making it flash as if it is re-running the create/kill instances over and over again.  But it is appearing upon collision now and tracking each respective knight.

EDIT: If I take out the 'Kill Sword Instance', then it does the full loop but for lots and lots of swords so I figured If I 'Kill Sword' at the end of it's loop maybe this would work.  I only know how to 'Do after x secs'.  (Which kinda worked), how do I tell it to do something at the end of it's animation loop?

UPDATE: I used an 'is animation still playing' to determine when to kill the sword, which worked a treat BUT the sword only recreates for one instance of the knight?  See code below.  (Thanks)

« Last Edit: December 28, 2014, 02:24:23 am by Northfield82 »