Example code of Platformer AI

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
darkfrei
Party member
Posts: 206
Joined: Sat Feb 08, 2020 11:09 pm

Re: Example code of Platformer AI

Post by darkfrei »

Gunroar:Cannon() wrote: Mon Mar 22, 2021 8:43 pm Procedural nap, want the enemy AI to preferably also be able to be used as a player companion. Though just looking for examples. Even java :ultrahappy:
If too far from player then pathfinding to the player.

Now we are need the pathfinding with jumps :)
User avatar
Gunroar:Cannon()
Party member
Posts: 253
Joined: Thu Dec 10, 2020 1:57 am

Re: Example code of Platformer AI

Post by Gunroar:Cannon() »

Gunroar:Cannon() wrote: Mon Mar 22, 2021 8:43 pm Procedural nap, want the enemy AI to preferably also be able to be used as a player companion. Though just looking for examples. Even java :ultrahappy:
Procedural map*, I can have a procedural nap anytime I want.
The closer the example to lua the better, can be any engine, any language though.

I've heard about using pathfinding to get to a point in the map, but with the rules being changed, like don't accept any node without a "solid" node(ground) underneath it, but I don't see how that could work with jumping and velocity calculations.
me: I don't always code but when I do it's done flawlessly.
also me:

Code: Select all

 function Gunroar:Cannon()
    for x, enemy in ipairs(self.allEnemies) do
        self:Cannon(enemy)
    end
end

Code: Select all

Lua Error: [file Gunroar.lua]:18: C stack overflow
User avatar
darkfrei
Party member
Posts: 206
Joined: Sat Feb 08, 2020 11:09 pm

Re: Example code of Platformer AI

Post by darkfrei »

Gunroar:Cannon() wrote: Tue Mar 23, 2021 9:32 am I've heard about using pathfinding to get to a point in the map, but with the rules being changed, like don't accept any node without a "solid" node(ground) underneath it, but I don't see how that could work with jumping and velocity calculations.
Some hidden hardcoded jump places, and all you need is a time between two points, actual position and target position.
User avatar
Gunroar:Cannon()
Party member
Posts: 253
Joined: Thu Dec 10, 2020 1:57 am

Re: Example code of Platformer AI

Post by Gunroar:Cannon() »

darkfrei wrote: Tue Mar 23, 2021 7:35 pm
Some hidden hardcoded jump places, and all you need is a time between two points, actual position and target position.
Can't hardcode due to procedural map, and thnx for the thoughts, though looking for example code.
me: I don't always code but when I do it's done flawlessly.
also me:

Code: Select all

 function Gunroar:Cannon()
    for x, enemy in ipairs(self.allEnemies) do
        self:Cannon(enemy)
    end
end

Code: Select all

Lua Error: [file Gunroar.lua]:18: C stack overflow
User avatar
darkfrei
Party member
Posts: 206
Joined: Sat Feb 08, 2020 11:09 pm

Re: Example code of Platformer AI

Post by darkfrei »

Gunroar:Cannon() wrote: Wed Mar 24, 2021 8:11 am
darkfrei wrote: Tue Mar 23, 2021 7:35 pm
Some hidden hardcoded jump places, and all you need is a time between two points, actual position and target position.
Can't hardcode due to procedural map, and thnx for the thoughts, though looking for example code.
Ok, not hardcoded, but analysed and cashed; for every block edge jump forward or jump up/down.
Something like ladder (easy for pathfinding), but jumps.
milon
Party member
Posts: 123
Joined: Thu Jan 18, 2018 9:14 pm

Re: Example code of Platformer AI

Post by milon »

Maybe it's better to think in terms of cached landing points. Then it doesn't matter if your enemies jump the same height/distance or not. Note that your procedural generator needs to be aware of the enemy's jumping capabilities to create navigable maps, unless you want them getting stuck or diving into pits. Anyway, as it generates maps, it marks the edges (or near-edges) of the pits as landing points. When the enemy wants to path to a different platform, it executes a jump when it's in jump range of that landing point. Jump range would be something you'd have to define per enemy class / AI.

EDIT: You may want to read about Dijkstra maps if you're not already aware.
http://roguebasin.roguelikedevelopment. ... kstra_Maps
This implementation is for a top-down rogue-like, but you can likely tweak it for a platformer. It likely won't have great performance, unless you consider each platform to be its own cell (rather than each pixel).
Post Reply

Who is online

Users browsing this forum: GVovkiv and 12 guests