Temperature system for a winter survival game.

Post Reply
pedka
New member
Posts: 6
Joined: Tue Jul 02, 2024 19:15
GitHub: not-pedka
In-game: pedka

Temperature system for a winter survival game.

by pedka » Post

Listen, I've never created a game before. I have very basic programming experience from ROBLOX and it's certainly not enough for what I want to achieve. I'll probably abandon this as soon as I get overwhelmed, but as for now I'm motivated. So here's the idea; I'd like to create a winter survival game where temperature is the core mechanic. I don't know how Luanti's API looks like yet, but I'm willing to learn it by trial and error. So, here's what I'd need:

Every step, nodes in the world exchange a portion their temperatures with neighbors, based on thermal resistance. Nodes with high resistance gain/lose temperature to other nodes more slowly. If there's no heat source (by that I mean a node with a constant temperature), the temperature should eventually equalize with the atmospheric temperature (based on attitude; the deeper you are the warmer it gets). If my reasoning is correct, this way blocks with high thermal resistance could be used to create rooms that when heated from, e.g., with a torch. will retain heat (even for some time if there's no active heat source). In addition, blocks that are difficult to heat up/cool down would additionally radiate with heat, extending the range of a heat source.

I'd like to implement such system, but I have no idea where to start. Can someone please help me? Maybe if i get an initial idea of how to approach this problem, I could push it forward myself. I don't know if it's possible, but i know that i'd need to give the built-in air block temperature and thermal_resistance properties. Additionally, I don't know how to scan the right nodes; looping through everything seems expensive and i care about optimization.

I prefer to learn from examples and hope it's not wrong to ask for code like this. If it is, I'm sorry. Thanks in advance.

User avatar
sorcerykid
Member
Posts: 1920
Joined: Fri Aug 26, 2016 15:36
GitHub: sorcerykid
In-game: Nemo
Location: Illinois, USA

Re: Temperature system for a winter survival game.

by sorcerykid » Post

This is certainly doable to some degree (no pun intended). My game server makes extensive use of weather and temperature based survival, including a "Temp Felt" HUD and even a vignette overlay to give a visceral indication of temperature extremes.

Image

https://github.com/sorcerykid/survival? ... me-ov-file

Players must be selective when venturing out in the cold (to avoid frostbite) or when mining in lava caves (so as not to get heatstroke) by wearing armor with suitable insulation and conduction properties. Similarly wielding a torch will give a warming sensation while holding an ice cube will result in a cooling effect.

Image

While the game mechanic on my server isn't quite as elaborate as you described (i.e. heat being confined to a specific room) it nevertheless does account for radiation sources. That is, a node can propogate heat radially or on contact, or even both (such as a furnace which will burn you when touched, but provide moderate warmth from a distance). This is accomplished by use of my Axon framework:

viewtopic.php?f=9&t=24721

Of course, in my case I'm focused on optimizing for server performance (network, CPU, etc.) rather than ultra-realism. But since your game is most likely intended for single-player on a local machine, you probably won't have those same constraints. I would be interested in seeing what direction you plan to take with your project!

User avatar
Mantar
Member
Posts: 688
Joined: Thu Oct 05, 2017 18:46
Contact:

Re: Temperature system for a winter survival game.

by Mantar » Post

We have a fairly extensive system for this in Exile, which works acceptably well in multiplayer and on low end machine. The primary functionality is in climate/temperature.lua.
Lead dev of Exile, git repo: https://codeberg.org/Mantar/Exile

User avatar
Skamiz Kazzarch
Member
Posts: 694
Joined: Fri Mar 09, 2018 20:34
GitHub: Skamiz
In-game: Skamiz
Location: la lojbaugag.

Re: Temperature system for a winter survival game.

by Skamiz Kazzarch » Post

Couldn't find it when I first read this topic, but happened on it by coincidence today. Yet another mod that does temperatures: Temperature Survive

A more detailed response to your suggestions:
In practice, simulating temperature for every single node is not feasible from a performance perspective. Maybe if it was a feature built in into the engine? But implementing it just through the API would be way too slow for sure.

You could cut out a lot of the calculations by ignoring large volumes of air and underground stone, presuming that they are already well mixed. Maybe updating the nodes at random rather then every node every time? And probably a lot of other things.
Generally you will want to focus the mechanic as tightly as you can around the stuff that is most directly relevant to the player. And even then you might not get away with it without knowing specialized optimization techniques. Making faithful yet performant simulations is not a simple mater.
Last edited by Blockhead on Tue Mar 10, 2026 01:22, edited 1 time in total.
Reason: Fix link to temperature survive (was this thread)

User avatar
Don
Member
Posts: 1893
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

Re: Temperature system for a winter survival game.

by Don » Post

You might find myweather useful. https://donbatman.github.io/myweather.html
My mods on ContentDB. My profile on the forum. Over 50 000 Downloads!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest