Making an actor move around tiles in a 4 way pattern. (reopened)

I have this enemy that moves around tiles clockwise or counterclockwise in a 4 way pattern. All my tiles have a square collision block so no diagonal movements or anything. I'm not sure how to explain this bug basically it would follow along a wall. Any suggestions on how to go about doing this?

« Last Edit: April 15, 2011, 01:25:11 pm by blackbishop89 »

Greg

  • *
  • Posts: 1259
If I'm understanding correctly (and it's possible that I'm not), there are a few ways to do it.

1) Check which direction you're moving in (clockwise or counter), detect the collision, and then change directions appropriately.  For instance, if you're set up to move clockwise, you're currently moving to the right, and you have a right side collision -- update the movement to move down.  If you then collide on the bottom, update the movement to move left.

2) Hardcode the offset values from the origin.  For instance, it's now 200 horizontal pixels from the origin - now move down instead of to the right.  Ok now we're 200 pixels vertically from the origin, now move left, etc...

3) (Plug) Use the cutscene pack.  Place motion (or message) triggers in your scene that will tell your enemies when to change directions.  This may not be feasible if you have a large number of enemies in your scene. 

« Last Edit: April 08, 2011, 09:43:12 am by Greg »

Alexin

  • *
  • Posts: 3127
You're facing a common introductory problem of AI, which is usually solved with simple reactive agents.

Imagine you're the actor and you're facing north, while moving to your right (east). Suddenly, you hit a wall and feel it on you right side. At this moment, you have to decide whether you move north or south. If you decided to move clockwise, then you move south, but if you decided for counter-clockwise then you move north.

This approach require you to know in which direction you're traveling, which side was hit upon a collision and whether the overall movement is clockwise or counter-clockwise.
One advantage is that you can place you actor on the scene wherever you want and it will adapt to the environment (the map). Just define those rules and it works out the box without complications.
"Find the fun"
alexin@stencyl.com