Procedurally generated creatures

Post Reply
User avatar
MirceaKitsune
Member
Posts: 970
Joined: Sat May 21, 2011 22:31
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune
Location: Romania, Bucharest

Procedurally generated creatures

by MirceaKitsune » Post

I haven't yet made such a mod nor am currently planning to, but had the idea in mind for a while and wanted to ask before it gets forgotten. I'm not expecting anyone to have already made such a thing though I may be surprised; Was rather curious how doable it is conceptually, and what the best approach would be if anyone ever tried it.

Minetest is fun because most parts are procedurally generated. Even if a few things such as tools or materials or trees are fixed... which too could be randomized if we really wanted, I can think of ways to mix names and sprites for random tools / ores / materials registered when the world is launched. I'm more curious about the hardest thing on the list: What about generating random creatures? Perhaps even a creature editor that works from a formspec, I can see something a bit like Spore conceptually!

The idea is inspired by a tree generator I made long ago... might still have the old code for it somewhere, haven't bothered looking since the concept is so simple I'd rather redo it from scratch: The sapling replaced itself with a log starting with a life value of 1... each iteration the log reproduced upward with the child node having a slightly lower life, occasionally it would replicate sideways to create branches, at other times it spends a tiny amount of life to spawn leaves instead. You could define different tree shapes by adjusting the replication parameters and branching frequency. When placed by the mapgen saplings grew instantly so they worked be used generate forests the player can discover... it would of course grow slowly when placed by the player, I think I wanted to account for temperature and humidity and sunlight to allow periodically regaining life based on that.

So if it works for trees why not animals and even alien villagers or player models? Everything is made of cubes using low-res textures, even a basic result works as long as it makes sense. Of course this isn't by far as easy as static trees: Mobs are moving entities that require animated models! Nodeboxes are closest to what I'm thinking of, but I think they remain supported for meshes only and definitely can't be animated. So the only reasonable idea is some kind of generic rigged mesh, with different movement animations and blocks that can be toggled and re-textured independently to cover all use cases... alternatively we could have an invisible armature and attach different models to it; If our Irrlicht fork allows resizing bones to get different proportions or remove some parts, I can see this working out rather nicely!

With that in mind I am thinking something close to my tree concept: Define a simple setting object acting as DNA, some rules it can be randomized and / or evolve by, produce a few default creatures that are initially spawned on the world, then have their offspring slightly mutate those settings so similar but new creatures are spawned each time. If there's a way to determine the amount of movement speed or damage each creature can do based on its shape, it could even simulate natural evolution so creatures that are too broken don't get produced.

wheat8
Member
Posts: 41
Joined: Sat Jul 20, 2024 13:06
Location: France

Re: Procedurally generated creatures

by wheat8 » Post

Sorry I misunderstood, off topic.
Last edited by wheat8 on Sat Oct 05, 2024 14:57, edited 1 time in total.

User avatar
FreeLikeGNU
Member
Posts: 311
Joined: Tue Oct 28, 2014 02:50
GitHub: FreeLikeGNU
IRC: freelikegnu
In-game: FreeLikeGNU

Re: Procedurally generated creatures

by FreeLikeGNU » Post

I did something like this with goblins and particularly witches but it's more RNG than proc gen. Instead of evolving as you are suggesting, they are randomly generated with many variables for names, quests, coloration, size, and accessories (using animated attachments) perhaps that code and the include blender files could be useful to your endeavor?

User avatar
MirceaKitsune
Member
Posts: 970
Joined: Sat May 21, 2011 22:31
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune
Location: Romania, Bucharest

Re: Procedurally generated creatures

by MirceaKitsune » Post

I actually started working on a concept in this regard... sort of, they aren't randomized right now but definitely something I'd call procedural. Been curious whether moving snakes made out of nodes are a thing that would be possible, came up with a sphere drawing algorithm and put it in practice: Just managed to get the mod stable enough to be considered good API wise, if it's still in early stages at the moment but good enough to test locally.

https://github.com/MirceaKitsune/minetest_snake

User avatar
FreeLikeGNU
Member
Posts: 311
Joined: Tue Oct 28, 2014 02:50
GitHub: FreeLikeGNU
IRC: freelikegnu
In-game: FreeLikeGNU

Re: Procedurally generated creatures

by FreeLikeGNU » Post

Oh wow, these would be cool! I placed a snake heart [snake_default] but it did not move or grow. The shape/concept kinda reminds me of the Ohmu from Nausicaä of the Valley of the Wind
edit: further investigation found that they will move toward a meselamp. Wow that's cool, very Ohmu-like!
Interesting behavior when lamp is placed underwater
Screenshot_2024-10-04_05-49-26.jpg
Screenshot_2024-10-04_05-49-26.jpg (325.96 KiB) Viewed 1071 times

User avatar
MirceaKitsune
Member
Posts: 970
Joined: Sat May 21, 2011 22:31
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune
Location: Romania, Bucharest

Re: Procedurally generated creatures

by MirceaKitsune » Post

Yeah I temporarily set the mese lamp as a target, glows like a beacon and is easy to find for testing.

I use the builtin pathfinding option so there's unfortunately no easy way to filter out which nodes they travel through, which by default includes all non-solid types: They will leave behind holes and trails like that, which looks alright for terrain but is more of a pain when it comes to water. Attempting to fix it would be too complex and I'm trying to keep the API simple; It's why I think the minetest.find_path function needs a few more parameters for some use cases.

User avatar
MirceaKitsune
Member
Posts: 970
Joined: Sat May 21, 2011 22:31
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune
Location: Romania, Bucharest

Re: Procedurally generated creatures

by MirceaKitsune » Post

Pushed numerous fixes today, such as head turning or following players that wield the right items. One fix is checking the path and making sure it doesn't cross any non-walkable nodes, if it does the path will now cut off: By default air is defined as the only walkable, for a snake meant to be underwater you can use a water node which will leave water nodes behind instead. Might properly define actual nodes and a final shape later, eventually I might randomize parts of the "DNA" to make each individual more unique!

Image
Image

User avatar
FreeLikeGNU
Member
Posts: 311
Joined: Tue Oct 28, 2014 02:50
GitHub: FreeLikeGNU
IRC: freelikegnu
In-game: FreeLikeGNU

Re: Procedurally generated creatures

by FreeLikeGNU » Post

Hmm I could not get them to follow a meselamp with the latest update fd6db22.
Screenshot_2024-10-05_07-31-49.jpg
Screenshot_2024-10-05_07-31-49.jpg (89.28 KiB) Viewed 997 times

User avatar
MirceaKitsune
Member
Posts: 970
Joined: Sat May 21, 2011 22:31
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune
Location: Romania, Bucharest

Re: Procedurally generated creatures

by MirceaKitsune » Post

It works in the right conditions. Make sure the head isn't buried, that's the most common cause for me: If the nose is poking through the ground pathfinding will fail. Later on creatures will be spawned from an egg, till then the head is still placed manually... when doing so build up 4 or 5 dirt nodes then place the root node on top of that.

User avatar
FreeLikeGNU
Member
Posts: 311
Joined: Tue Oct 28, 2014 02:50
GitHub: FreeLikeGNU
IRC: freelikegnu
In-game: FreeLikeGNU

Re: Procedurally generated creatures

by FreeLikeGNU » Post

Snake was moving along fine and was near water when I encountered this crash (from commit 952b633):

Code: Select all

2024-10-06 06:45:02: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'snake_default' in callback node_on_timer(): ...t-dev/minetest/bin/../mods/minetest_snake/snake/init.lua:83: bad argument #1 to 'ipairs' (table expected, got nil)
2024-10-06 06:45:02: ERROR[Main]: stack traceback:
2024-10-06 06:45:02: ERROR[Main]: 	[C]: in function 'ipairs'
2024-10-06 06:45:02: ERROR[Main]: 	...t-dev/minetest/bin/../mods/minetest_snake/snake/init.lua:83: in function 'shapes_get'
2024-10-06 06:45:02: ERROR[Main]: 	...t-dev/minetest/bin/../mods/minetest_snake/snake/init.lua:228: in function <...t-dev/minetest/bin/../mods/minetest_snake/snake/init.lua:96>

User avatar
MirceaKitsune
Member
Posts: 970
Joined: Sat May 21, 2011 22:31
GitHub: MirceaKitsune
IRC: Taoki
In-game: MirceaKitsune
Location: Romania, Bucharest

Re: Procedurally generated creatures

by MirceaKitsune » Post

FreeLikeGNU wrote:
Sun Oct 06, 2024 13:47
Snake was moving along fine and was near water when I encountered this crash (from commit 952b633):

Code: Select all

2024-10-06 06:45:02: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'snake_default' in callback node_on_timer(): ...t-dev/minetest/bin/../mods/minetest_snake/snake/init.lua:83: bad argument #1 to 'ipairs' (table expected, got nil)
2024-10-06 06:45:02: ERROR[Main]: stack traceback:
2024-10-06 06:45:02: ERROR[Main]: 	[C]: in function 'ipairs'
2024-10-06 06:45:02: ERROR[Main]: 	...t-dev/minetest/bin/../mods/minetest_snake/snake/init.lua:83: in function 'shapes_get'
2024-10-06 06:45:02: ERROR[Main]: 	...t-dev/minetest/bin/../mods/minetest_snake/snake/init.lua:228: in function <...t-dev/minetest/bin/../mods/minetest_snake/snake/init.lua:96>
Try latest Git: A lot of that stuff was just changed, I'm now doing proper hashing and shape caching which improved movement performance 10x. If it still happens please post a new crash message so I can see the exact line on current main branch.

I just finished adding eggs which are now provided in the created inventory instead: Place those on the ground and wait for a few seconds. This automatically places the head at the right height and avoids ground intersection, avoid placing it near tall terrain to prevent sticking.

I may work on nodes next then make a proper thread as this one was meant to be more generic. Funny enough I'm not sure how to handle digging: The plan is to add realistic blood and flesh rotting, not sure if some may complain about that... I never had gore as a deliberate plan per say, it's just that these are node snakes in a destructible environment so to emulate realism I have to handle that somehow, and I don't want to go with the green / blue / whatever other color blood approach just to avoid proper emulation. The snake regenerates as it moves anyway so I'll likely have nodes transmit a life value to each other to properly detect damage and inform the root node.

Post Reply