Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get Sanity to drain in the dark and increase in the light?
DRedshot Offline
Senior Member

Posts: 374
Threads: 23
Joined: Jun 2011
Reputation: 11
#11
RE: Get Sanity to drain in the dark and increase in the light?

Here's how I would have done it Tongue
Spoiler below!

float sanityFactor = 10.0f;
float curSanity = 100.0f;
float oldSanity = 100.0f;

void OnStart()
{
SetPlayerSanity(100.0f);
AddTimer("SanityTimer", 0.5f, "UpdateSanity");
}

void UpdateSanity(string &in asTimer)
{
curSanity = GetPlayerSanity();
float temp;
if(curSanity < oldSanity)
{
temp = curSanity - sanityFactor;
SetPlayerSanity(temp);
}

if (curSanity >= oldSanity)
{
temp = curSanity + sanityFactor;
if(temp <= 100.0f)
{
SetPlayerSanity(temp);
}
else
{
SetPlayerSanity(100.0f);
}
}

curSanity = GetPlayerSanity();
oldSanity = curSanity;
AddTimer("SanityTimer", 0.5f, "UpdateSanity");
}


I bolded the thing you missed. You had to recalculate the current sanity after modifying it with the sanityFactor.
Also, I changed a '>' to a '>=' because sanity doesn't recover in light. You are in light when sanity is equal to it's previous value Smile

Hope this helps.

Edit: Bold doesn't work in code format :/

Also, I'd lower the sanity factor by quite a lot, losing 20 sanity per second seems a bit too much, maybe make it = 0.5-1

(This post was last modified: 04-13-2012, 02:12 AM by DRedshot.)
04-13-2012, 02:06 AM
Find


Messages In This Thread
RE: Get Sanity to drain in the dark and increase in the light? - by DRedshot - 04-13-2012, 02:06 AM



Users browsing this thread: 1 Guest(s)