I have script which controls air temperature : var temperature : float = 75f ;
and (human) body temperature : var bodytemperature : float = 98.6f ;
. As the player walks/runs/jumps his body temperature increases by a small decimal : var TempRateMovement : float = .0003;
. I have been trying to make my temperature variable affect the TempRateMovement. As the the (air) temperature increases, i want the TempRateMovement to increase, and as it decreases the rate also will decrease. How can i calculate this?? Thank you!
Here is the TemperatureController.js:
#pragma strict
var temperature : float = 75f ; //or any other value;
var bodytemperature : float = 98.6f ; //or any other value;
var source : AudioSource;
var rectHeight: float;
var rectLength: float;
var style: GUIStyle;
var styletext : GUIStyle;
var humanstyle : GUIStyle;
var cloudstyle : GUIStyle;
var normalSymbol : Texture2D;
var moving : boolean = false;
var sprinting : boolean = false;
var idle : boolean = false;
var temperatureSymbol : Texture2D;
var humanTex : Texture2D;
var cloudTex : Texture2D;
var hotSymbol : Texture2D;
var coldSymbol : Texture2D;
var SomewhatCold : Texture2D;
var SomewhatCold2 : Texture2D;
var SomewhatHot : Texture2D;
var SomewhatHot2 : Texture2D;
var TempRateMovement : float = .0003;
var TempRateIdle : float = .00025;
var player : FPSRigidBodyWalker;
var headbob : Ironsights;
function Update (){
TempAffectsOnPlayer();
styletext.normal.textColor = Color.Lerp(Color(0, 0.83137254902,1,255), Color(1,0.21568627451,0.21568627451,255), temperature/98.6);
if (temperature >= 101){
temperatureSymbol = hotSymbol;
}
else
{
if (temperature > 60 && temperature <85){
temperatureSymbol = normalSymbol;
}
}
if (temperature <= 10){
temperatureSymbol = coldSymbol;
}
if (temperature <= 60 && temperature > 32){
temperatureSymbol = SomewhatCold;
}
if (temperature <= 32 && temperature > 10){
temperatureSymbol = SomewhatCold2;
}
if (temperature >= 85 && temperature < 95){
temperatureSymbol = SomewhatHot;
}
if (temperature >= 95 && temperature < 101){
temperatureSymbol = SomewhatHot2;
}
if (Input.GetAxis("Horizontal") || Input.GetAxis("Vertical"))
{
moving = true;
idle = false;
bodytemperature += TempRateMovement;
}
else
{
moving = false;
idle = true;
TempRateMovement = .00003;
if (bodytemperature > 98.6)
bodytemperature -= TempRateIdle;
}
if (moving && Input.GetKey("left shift") && !idle)
{
sprinting = true;
TempRateMovement = .00005;
}
else
{
sprinting = false;
}
if (Input.GetKeyDown("space")){
JumpTempIncrease();
}
}
function OnGUI () {
var actualTemp = temperature-.05;
var actualbodyTemp = bodytemperature-.05;
GUI.Box (Rect(Screen.width - rectLength,Screen.height-rectHeight,200,80), temperatureSymbol, style);
GUI.Box (Rect(Screen.width+20 - rectLength,Screen.height-rectHeight,200,80), cloudTex, cloudstyle);
GUI.Label (Rect(Screen.width+1 - rectLength,Screen.height-rectHeight+60,200,80), actualTemp.ToString("f1") + "°F", styletext);
GUI.Box (Rect(Screen.width - rectLength,Screen.height-rectHeight-100,200,80), temperatureSymbol, style);
GUI.Box (Rect(Screen.width+20 - rectLength,Screen.height-rectHeight-100,200,80), humanTex, humanstyle);
GUI.Label (Rect(Screen.width+1 - rectLength,Screen.height-rectHeight-40,200,80), actualbodyTemp.ToString("f1") + "°F", styletext);
}
function JumpTempIncrease (){
yield WaitForSeconds (1.0);
bodytemperature += TempRateMovement + .00002;
}
function TempAffectsOnPlayer ()
{
//Movement && Headbob
if (temperature > 101 )
{
//everything greater than 101
player.walkSpeed = 1.8;
player.jumpSpeed = 0;
headbob.WalkHorizontalBobAmount = 0.25;
headbob.WalkBobPitchAmount = 0.065;
headbob.WalkBobSpeed = 4;
headbob.WalkBobRollAmount = 0.1;
player.sprintActive = false;
}
if (temperature < 101 && temperature >95)
{
// between 101-95
player.sprintActive = false;
headbob.WalkHorizontalBobAmount = 0.2;
headbob.WalkBobPitchAmount = 0.04;
headbob.WalkBobSpeed = 9;
headbob.WalkBobRollAmount = 0.07;
player.walkSpeed = 4;
player.jumpSpeed = 0.6;
}
if (temperature < 95 && temperature > 85)
{
//between 95-85
player.sprintActive = true;
headbob.WalkHorizontalBobAmount = 0.11;
headbob.WalkBobPitchAmount = 0.0175;
headbob.WalkBobSpeed = 12;
headbob.WalkBobRollAmount = 0.01;
player.jumpSpeed = 1.3;
}
if (temperature < 85 && temperature > 75)
{
// between 85-75
player.runSpeed = 7.8;
headbob.WalkHorizontalBobAmount = 0.14;
headbob.WalkBobPitchAmount = 0.02;
headbob.WalkBobSpeed = 11;
headbob.WalkBobRollAmount = 0.03;
player.jumpSpeed = 2.6;
}
else
{
if (temperature < 75){
player.runSpeed = 9;
headbob.WalkHorizontalBobAmount = 0.11;
headbob.WalkBobPitchAmount = 0.0175;
headbob.WalkBobSpeed = 12;
headbob.WalkBobRollAmount = 0.01;
player.jumpSpeed = 3;
}
}
}