Can an enemy actor follow the X-position of the Player?

ZeroRaven87

  • Posts: 7
I'm running into a rut when it comes to using this creator.
More to the point, I want to have generated enemy actors note and follow the X-Position of the player actor.
Previously I've used "Gamesalad" and it was a fairly straight forward matter of using a game attribute (PlayerPosX) to update with the player X Position every so often and then have the enemys reference that and move them towards it.

Presently my coding in Stencyl is:

Scene Behavior:
Do every 1 seconds:
  Set game attribute named (PlayerPosX) to (X) of (Player)

Actor (enemy) Behavior:
Always
  Push (Self) (Gently) towards (xdir [PlayerPosX] ydir
  • ) at (10)


Said behaviors arent working. Is there a simpler idea to have an actor track the player?

SadiQ

  • Posts: 1795
It should work. Try to see if pushing sharply makes a difference. If not then try a print block inside the enemy behavior to see what's the value of the game attribute (PlayerPosX)
Proud member of the League of Idiotic Stencylers! Doing things in Stencyl that probably shouldn't be done.

PhilIrby

  • Posts: 545
Stencyl has a prepackaged  Follow Target behavior.  In the Dashboard  open an actor type  that you want to have  the behavior- select behavior tab and select the + at bottom left, look in the motion folder.

ZeroRaven87

  • Posts: 7
Stencyl has a prepackaged  Follow Target behavior.  In the Dashboard  open an actor type  that you want to have  the behavior- select behavior tab and select the + at bottom left, look in the motion folder.

But the follow target behavior will track the X and Y values of the Player actor.
Would the best way to solve that be to edit said behavior and remove the blocks for tracking the Y values?

ZeroRaven87

  • Posts: 7
Removing the set distance Y block as well as changing the Y values in the following 2 blocks yielded satisfactory results. No will this also work for enemy actors which are created as the scene progresses? Or will it only apply to enemy actors already preplaced in the scene?

PhilIrby

  • Posts: 545
If the Actor Type  has the behavior then created instances of that actor would  also have it.

ZeroRaven87

  • Posts: 7
Thanks Phillrby.
Glad to see the members on here are as helpful if not more so then the members on the Gamesalad forum.

letmethink

  • *
  • Posts: 2545
I would like to point out why your original code wasn't working. Pushing gently at force 10 is negligible. If you pushed sharply your code should hopefully work.
~Letmethink

PhilIrby

  • Posts: 545
Sorry, I had never used  this behavior before and after trying it out, find it only works for enemies placed in the scene  and customized.  I think this is primarily to set the value for TargetActor for each enemy.  Should of tested before I replied to you.
 

ZeroRaven87

  • Posts: 7
OK so do you know if there is a better alternative to achieve me desired effect?

PhilIrby

  • Posts: 545
We can modify the Follow Target so it will not require actors to be customized in the scene. Follow these steps;

1. In the scene, create an actor attribute named Target.
   Create a scene behavior named findTarget which sets the
   actor attribute Target to your player.
       
2.  In the Follow Target behavior modify the created event
    by setting Target Actor to the scene Target attribute.   

cincos300

  • Posts: 19
This problem was solved with an actor behavior that sets the target to one of the on-screen _ActorTypeTarget. You can find it on the forge.
Founder and CEO of Infinity Systems