How do I Create Platformer AI?

Get help using Construct 2

Post » Tue Nov 22, 2016 8:32 pm

I want to create a an AI where an enemy moves from side to side. How Can I do this I tried use the sine behavior but I don't know how to make it go further distances.

Posts: 12
Reputation: 349

Post » Tue Nov 22, 2016 8:49 pm

If you mean to have the enemy move back and forth between 2 points (as in from one end of a platform to the other and back).
A simple way is to put an invisible object at each end of the platform (or patrol line) and have the enemy reverse direction when he collisions with said object.
Posts: 2
Reputation: 179

Post » Tue Nov 22, 2016 10:02 pm

First you need logic. Then apply the logic.
From side 2 side, i suppose there are platforms between the sides.

Set the controls in the platform properties to custom. Now we have to code every move it will make.

- When there are no decisions to make at its current position.
Just keep going in the current direction.
To do that you need a instance variable that holds the direction.
Use the action 'Simulate control' to simulate left/right according the instance variable.

-When there is a wall in the left or the right.
Platform has a condition 'Is by wall'. Change the instance variable to reflect the change in direction.

-When it comes to a place where it has to decide to jump on or walk under a platform.
Place invisible object on those places where a decision is needed. Detect an overlap.
Pick a random (expression choose(0,1)). If 0 jump

-When it comes to a place where has to decide to just fall off or to jump to another platform.
Same system, place invisible objects. Detect an overlap.
Pick a random (expression choose(0,1)). If 0 jump

And so on. Build the logic. Apply the logic.

-When it is seeing the player
To look for the player you can use the Line-of-sight behavior.
Calculate (based on x differences) what direction the player is.
Change the direction instance variable according.
Eventual look if the player is jumping, if jumping run other direction.

And so.....
Posts: 2,493
Reputation: 21,450

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests