r/howdidtheycodeit • u/WombatHat42 • Jan 18 '22
Question How is a player temperature that is affected by the environment done?
When doing a player HUD, how do they do it to involve player temperature? For instance, you go into a snowy area and your body temp drops slowly overtime until you’re hypothermic and causes damage and the HUD displays from a normal temp 98.6 and drops a increment per time in that area.
16
Upvotes
13
u/Seubmarine Jan 18 '22
If you implemented biome there is a way for the player to detect it, like a big collision box, in that case you just apply a temperature to the player over time and that's it. Buf please tell if you have a game in mind ?
32
u/ctothel Jan 19 '22
I’ve done this before, as follows:
The player object knows what area it’s in, and that area has an ambient temperature.
The player object can detect heat-emitting objects (like the sun, or a heater), and raycasts to them to detect whether they’re in line of sight. If they are, measure the distance to them and apply a static temp increase (for the sun) or an inverse square law increase (for nearby objects) to determine how much hotter the player should be. That way you get an interesting shade/sun effect too, or an effect where getting closer to fire makes you warmer, but not if you’re behind a barrier.
7
u/Alawliet Jan 19 '22
Umm you might need to elaborate on what kind of system your thinking of. Because showing a temperature on a character and making it have an effect is simple. Temperature can just be a number you store on your character and change it depending on conditions. If it drops below a certain value you can take damage etc.
But if your getting more complicated like BTOW it's a whole other conversation.