|
I have this health regeneration script, and that works fine. Except one problem where if I do something like jump health regenerates faster than it's suppose to. Here's the script: I think it has something to do with the Time.deltaTime, but I'm not to sure.
(comments are locked)
|
|
First try changing Time.deltaTime to Time.smoothDeltaTime. This'll smooth it out so that if your framerate takes a big hit (due to jumping, moving around, or other things that'd cause a lot of rendering). If that doesn't work, try doing this in FixedUpdate() instead of Update(). FixedUpdate happens at a fixed rate, which seems to be more of what you want. With Update, if you have lots of Draw calls, this is going to slow it down, causing the time to be inconsistent. Additionally, change Time.deltaTime to Time.fixedDeltaTime so that it will be responding to the appropriate signal. Hopefully that works, but I can't tell because now my problem is that it regenerates too fast. And it only regenrates when I set HealthRegenRate to 50, and that's too fast.
Jul 20 '12 at 02:33 AM
chrisall76
(comments are locked)
|

I can't find anything wrong with this code, the line hitPoints += healthRegenRate * Time.deltaTime; should ensure that hitPoints is increased by one each second. In the script the healthRegenRate isn't being changed or anything so this script shouldn't be the problem.. Could you add the script in which you are calling the actions such as jump etc?
it could be Time.deltaTime remember that Time.deltaTime, as implied by the name, is simply the amount of time that has passed since the last frame.
edit: meant to type couldn't i hate english trololol thx anyways i think @merry_christmas explained a bit better
Time.deltaTime is a useful way of making a variable always increase at the same rate, since you are adding the time that has passed since the last frame to that variable each time the Update() function is called.. This means that if you added Time.deltaTime to a variable, then after one second the variable would have a value of 1 (Frame rate doesn't matter). With this in mind, Time.deltaTime can't be the reason that the healthRegenRate variable is increasing faster when the player jumps :)