-
What do you want to achieve? I’m making sandbox game about space exploration. And I want to create temperature mechanics. For example, when I turn on laser, then it and its surroundings get hotter. If it’s too hot, some parts may combust. On the other side, when I go to cold planet, then player and maybe some machines need heating, to prevent freezing. Also, I want to make that temperature mechanics work correctly both in atmosphere, and in vacuum.
-
What is the issue? I want to make such temperature system both realistic, and performant.
-
What solutions have you tried so far? I was thinking about few solutions. I haven’t make any code for temperature yet.
- Simple and basic solution: machines which heat up (i.e. laser) just create a invisible “bubble” of heat. And temperature in given point would be just ambient temperature + sum of bubbles temperature changes. However, this is very unrealistic. And player cannot make any kind of thermal insulation. I would want to avoid this solution.
- Better solution, more realistic, but possibly laggy: each part has got a specific heat, current thermal energy and current temperature.
When two parts touch each other, then they gradually exchange heat.
If there is atmosphere, then gradually change temperature of all parts to air temp.
All parts which are in direct line-of-sight gain thermal energy from star.
All parts periodically do raycast in random direction. If ray hits other part, then exchange temperature. Else lose some heat. This is temperature exchange via thermal radiation.
This solution would be more realistic, but also more laggy, primarily due to raycasts. - Similar to above, but less laggy: when exchanging heat via radiation, don’t do raycasts. Instead, find all parts in given distance, and exchange heat with them if there is direct line-of-sight between them.
- Similar to above, but yet less laggy: Exchange heat with all parts in given distance; don’t check if there is direct line-of-sight.
Maybe also don’t check line-of-sight between part and star.
I this game, there are many regions (server per region), and thus amount of part in one server won’t be very huge, but possible quite big.
I hope you’ll review my ideas how to do this, and maybe propose your own. For now, I think that one of two last solutions seem to be best.