Push toward


  • Posts: 20
I'm accelerating an actor every thick toward a specific position on the screen (100,100) with a behaviour attached to the actor. It works in an unexpected way (at least for me) it move towards 100,100 and then goes on while I expected it to carry on past 100,100 a bit, then stop and go back and, during time stop exactly at 100,100.

Why it's not like this?



  • *
  • Posts: 4645
The force block you're using is the following one, correct?

If so, you need to keep in mind that you're pushing it toward a location relative to the actor, and not a screen or scene location. Thus it will never reach 100,100.

To adjust for this, you'll need to push toward a value that is constantly adjusted by subtracting the actor's current X,Y position. If the actor passes 100,100, the calculations will cause the value to become negative and thus reverse the direction of force on that axis.

Edit: One final note is that it may never actually stop at 100,100 as you intend. The reason for this is that the force applied can push an actor just past the target mark each time the actor is updated. It fact it's very unlikely that the values will ever match exactly. You can even see this in my Small Squad demo (it's here on stencyl.com if you look under my profile). If you use the arrow keys to move the squad left or right, they'll line up with the circles and stand still - but for some reason the same is never true when moving up and down (they jiggle in place a by one pixel back and forth).

Your best bet is to check if the actor is within a few pixels of the target and turn off the force if so.

« Last Edit: February 08, 2012, 03:23:05 pm by Hectate »
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.


  • Posts: 20
ahhhh I see, it's relative to the actor then.. but what If I put the behaviour under the scene? Then it would be relative to the screen?

EDIT: Is there also a way to directly push towards another object?

p.s. thank you very much