Give your Plat former Enemies AI

1

Stats

8,946 visits, 13,741 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 5 Mar, 2014. Last updated 19 Feb, 2019

Here's a sample of how I gave my enemies (Agent Sprite) AI to chase the player (Ninja Sprite) and attack the Ninja.

I give the Agent Sprite a Boolean variable called "Chasing". When some random event in the game is triggered and the variable changes to true, then the adjoining conditions kicks in.

I give Agent "8 direction behavior" and set the behaviors properties to left & right only and set "Use Default Controls" to No.

When the Agents X position is greater than (on the right side of Ninja) it Simulates pressing Left and sets the not mirrored property appropriately.

Since the Ninja can attack, run, and most importantly JUMP over the Agent, the Agent then has a lesser X coordinate compared to Ninjabox.X and the reverse set of conditions and events kick in below.

Notice that in a sub event, when the Agent is overlapping at an offset of 25 with the Ninja, his animation sets to "punching" and he attacks! he also "starts ignoring user input" so he doesn't push Ninja sprite backwards off a cliff (unless you want him to), because he wont stop otherwise.

Once Agent is no longer overlapping at an offset with -25, Agent cease the "punching" animation and returns to "walking animation" and starts chasing again until he makes contact.

Both sets of conditions have the same two sub events. The first set of conditions on top is just collapsed, so I could fit it in the image.

Just in case your curious how I measure damage to Ninja in this scenario. The Ninja loses health points at different rate of speed (depending on the Enemy he's in contact with ) for every second he's overlapping at an offset of 25.

Hence the Ninja's health bar goes down.

Enjoy!

This is code above

Agents' Y coordinate is 302, so by adding the above, keeps agent from being knocked off his Y coordinate when he comes into contact with a solid object or the Ninja.

Note: Agent has "solid" behavior and Ninja has "Platform" behavior. (But Should not matter)

I cant give this capx because it's part of a large project, however I will take a look at yours or I will make one for you if you request and the above doesn't solve your problem.

.

  • 0 Comments

Want to leave a comment? Login or Register an account!