How can i activate the "follow target" behvaior in an actor when first created?

EXOUSTIA

  • Posts: 47
Hello  :)
I am making a simple 8-bit game, and i have run into a problem. I would like my enemies to chase my player, but i can only get this to happen through the follow target behavior, which has to be configured for all appropriate actors on the stage. However, I don't want to put my enemies on the stage initially, I want them to spawn after time. but, whenever I set a stage event to create an enemy every 5 seconds, the enemy does nothing because the follow target behavior hasn't been configured; yet i can only configure it if the enemy has been placed initially on the stage. does anyone think they have a solution?  :-\

« Last Edit: August 13, 2012, 09:57:42 am by EXOUSTIA »

captaincomic

  • *
  • Posts: 6109
Hi
You can use the the <for <Actor>, set _ to _ for behavior _> block to set the target at runtime.
For example:
<for <Enemy1> set "_TargetActor" to <Player> for behavior "Follow Target">

docskull

  • Posts: 65
What if the player is also added at runtime? (I have a multiple character choice)

sentenza

  • Posts: 55
Create the actor, then set the target for the "last created actor"


docskull

  • Posts: 65
Sorry, but how to get the "PlayeractorID" for the block you mentioned?

« Last Edit: September 18, 2012, 10:40:41 am by docskull »

Innes

  • *
  • Posts: 1963
The PlayerActorID is an attribute which (in this case) is used to store the Actor ID of the last created actor so you can access it later.

If you're not sure about Attributes, you'll need to learn about them to make any progress, so have a look at Stenclypedia or, on www.TheStencylBlog.com there's a tutorial.
Visit www.TheStencylBook.com - the only published book for learning Stencyl.

sentenza

  • Posts: 55
"PlayerActorID" is an attribute that references the target actor - you set it just after creating that actor.

docskull

  • Posts: 65
Many thanks everyone!! This helped me a lot!

TurboHenry

  • Posts: 1
I am having the same problem and can't get it to work can some one give me more details