How do I prevent 8-direction tracking enemies from jittering

Get help using Construct 2

Post » Fri Sep 02, 2016 2:04 pm

Hi, I'm making a game a top-down 8-direction movement perspective. One of the basic AI systems most of my enemies have is one that allows them to follow the player, it's a very simple implementation with no frills, just "if the player is here, simulate movement in this direction" like so.

Image
(obj_legs is my player's body hitbox object)

The problem is, when they align with the player on the X or Y axis, they constantly switch between up/down or left/right, causing this weird slow and jittery movement. Is there a better way to do this real simple AI that would prevent that?
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Fri Sep 02, 2016 5:14 pm

To avoid jittering movement, it's best to use a proper AI follow code.

To stop an enemy AI from jittering, we could use a variable like this.

https://www.dropbox.com/s/1g0lseyx71z9h ... .capx?dl=0

My recommendation is to use a simple set of events with variables like my next example.

By the way, I made this myself.

https://www.dropbox.com/s/iwftjcj2izc6j ... .capx?dl=0

1. Try approaching the enemy to be on enemy's line of sight.
2. Get caught. Enemy will stop.
3. Run away. Enemy will stay in the stopped state.
4. Approach the enemy again to provoke. Enemy will follow again.
B
11
S
6
G
15
Posts: 256
Reputation: 9,207

Post » Fri Sep 02, 2016 6:21 pm

This is how I handled the issue.

Video
B
56
S
15
G
13
Posts: 826
Reputation: 17,645

Post » Fri Sep 02, 2016 8:35 pm

Tekniko wrote:This is how I handled the issue.

Video

Thank you! This is exactly what I was looking for, I feel like a dummy for not trying it. :lol:

Gmoney wrote:To avoid jittering movement, it's best to use a proper AI follow code.

To stop an enemy AI from jittering, we could use a variable like this.

https://www.dropbox.com/s/1g0lseyx71z9h ... .capx?dl=0

My recommendation is to use a simple set of events with variables like my next example.

By the way, I made this myself.

https://www.dropbox.com/s/iwftjcj2izc6j ... .capx?dl=0

1. Try approaching the enemy to be on enemy's line of sight.
2. Get caught. Enemy will stop.
3. Run away. Enemy will stay in the stopped state.
4. Approach the enemy again to provoke. Enemy will follow again.


Right now I don't have any enemies that would need this complex of an AI but I'll keep it in mind in case I ever do!
B
18
S
9
Posts: 103
Reputation: 1,817


Return to How do I....?

Who is online

Users browsing this forum: DharmaOne and 19 guests