Basic AI for 2D Sidescrolling Game

I am just tooling around with the idea of a 2D side scrolling fighting game and wanted to run through my understanding of how to implement some basic AI. Just to try and get something working I am making everything very simple and basic.

I was thinking of creating the enemy object, loading them into the scene, and using an invisible line or rect which is anchored to the enemy and will be used to detect the player through collision. If this invisible rect collides with the player object then the enemy’s AI goes to work and does something simply like begins moving towards the player and once the enemy and player objects are within certain distance, perhaps with a small random offset thrown in, the enemy begins to swing his sword and try to attack the player.

Does this sound about right? What type of event listener would I use to continually run in the background to check for the collisions? Is this event listener model impact the performance at all?

Thanks!

Hey I am currently developing a 2.5D SideScroller/Brawler and I am using a similar technique for my “chasing” enemies.

I could use RayCasting but this has been too performance heavy in my game so I decided to use a custom method to check for their “line of sights”.

I am basically looping through my enemy group and create an “invisible” (alpha = 0.01) rectangle* with physics properties for each of my enemies and check if there is any collision with my player.

If yes then I can set a few flags dependent on my needs and some other stuff.

The function is called by a timer every second and gives me very good performance even if there are many enemies on the screen at the same time. 

P.S.: *Do not use display.newLine() this will cause some bugs, always use a very small rectangle!

CineTek / Max

Thanks for the reassurance CineTek, I was going to initially try the display.newLine approach, thanks for the tip.

How well is Corona handling  2.5D perspective? I don’t see a lot of references for this style of game? 

Well, I am using parallax scrolling to achieve a 2.5D effect. It runs fine, you just have to control the different layers with something like a camera module (for example “Perspective” from the code section)

I have around 7 or 8 layers moving simultaneously and I had some performance issues at the very beginning - caused by the moving layers only(!). It all depends on your optimisation and coding skills. Now everything runs fine at 60 fps.

The upcoming graphics 2.0 update is capable of doing pseudo 3D games as seen on other forum threads.

Or did you mean isometric style games? :slight_smile:

CineTek / Max

I was thinking 2.5 as in isometric. Ultimately I want to create a game of this style, classic turn based RPG, homage to the good old PS1 days. I have chosen a simpler project since I am not a developer by trade and there will be a lot of learning and growing pains through the development process.

Then I can suggest you the Million Tile Engine “MTE” by one of the forum users. I am not sure if isometric view is supported as of now, but the developer behind the project wants to integrate it in the near future :slight_smile:

And the performance is incredible 

Looks amazing, I will be taking a greater look at this later, how does this compare to Lime which I think has become open source recently? 

I do not really know the maths behind Lime and MTE but I *think* that Lime is rendering all tiles at the same time. MTE is way faster and very well optimised. 

Both tools are using the same tile editor (Tiled) so you could play a little bit around with Lime. But it does not support isometric view (I think) and the code may be old. Many things have changed since the last *official* release but you can give it a try.

Hey I am currently developing a 2.5D SideScroller/Brawler and I am using a similar technique for my “chasing” enemies.

I could use RayCasting but this has been too performance heavy in my game so I decided to use a custom method to check for their “line of sights”.

I am basically looping through my enemy group and create an “invisible” (alpha = 0.01) rectangle* with physics properties for each of my enemies and check if there is any collision with my player.

If yes then I can set a few flags dependent on my needs and some other stuff.

The function is called by a timer every second and gives me very good performance even if there are many enemies on the screen at the same time. 

P.S.: *Do not use display.newLine() this will cause some bugs, always use a very small rectangle!

CineTek / Max

Thanks for the reassurance CineTek, I was going to initially try the display.newLine approach, thanks for the tip.

How well is Corona handling  2.5D perspective? I don’t see a lot of references for this style of game? 

Well, I am using parallax scrolling to achieve a 2.5D effect. It runs fine, you just have to control the different layers with something like a camera module (for example “Perspective” from the code section)

I have around 7 or 8 layers moving simultaneously and I had some performance issues at the very beginning - caused by the moving layers only(!). It all depends on your optimisation and coding skills. Now everything runs fine at 60 fps.

The upcoming graphics 2.0 update is capable of doing pseudo 3D games as seen on other forum threads.

Or did you mean isometric style games? :slight_smile:

CineTek / Max

I was thinking 2.5 as in isometric. Ultimately I want to create a game of this style, classic turn based RPG, homage to the good old PS1 days. I have chosen a simpler project since I am not a developer by trade and there will be a lot of learning and growing pains through the development process.

Then I can suggest you the Million Tile Engine “MTE” by one of the forum users. I am not sure if isometric view is supported as of now, but the developer behind the project wants to integrate it in the near future :slight_smile:

And the performance is incredible 

Looks amazing, I will be taking a greater look at this later, how does this compare to Lime which I think has become open source recently? 

I do not really know the maths behind Lime and MTE but I *think* that Lime is rendering all tiles at the same time. MTE is way faster and very well optimised. 

Both tools are using the same tile editor (Tiled) so you could play a little bit around with Lime. But it does not support isometric view (I think) and the code may be old. Many things have changed since the last *official* release but you can give it a try.