Question by
RicardoAntezana · Apr 09, 2016 at 07:29 AM ·
floatif-statementsif
Sprinting and Tiredness
Hey guys, I have a small issue, I would like my sprintSpeed variable to be proportional to the amount of energy my player has left, basically the more he sprints the slower he will sprint. I tried something like this, but it is not the desired effect:
var energy = 100.0;
var sprintSpeed = 12.0;
function Update ()
{
if(energy <= 100 && energy > 75)
{
sprintSpeed = 12.0;
}
if(energy <= 75 && energy > 50)
{
sprintSpeed = 10.0;
}
if(energy <= 50 && energy > 25)
{
sprintSpeed = 8.0;
}
if(energy <= 25 && energy >= 0)
{
sprintSpeed = 6.0;
}
}
Any help is appreciated
Comment
Best Answer
Answer by JigneshKoradiya · Apr 09, 2016 at 07:37 AM
var energy = 100.0; var sprintSpeed = 12.0;
function Update () {
sprintSpeed = 6.0+(0.06f*energy);
}