Example code of Platformer AI

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
darkfrei
Party member
Posts: 1168
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 :)
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
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.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
darkfrei
Party member
Posts: 1168
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.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
Gunroar:Cannon()
Party member
Posts: 1085
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.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
darkfrei
Party member
Posts: 1168
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.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
milon
Party member
Posts: 472
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).
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 19 guests