• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Need an equation.

T

Thunder Lion

Guest
I am looking for an equation that will allow the following concept:

I have a fixed value, that must be modified by another variable.

They must be apart of an equation that results in being higher if the player reduces another variable and remain neutral toward the fixed variable if the player keeps this other variable untouched.

Again I have the variable swingspeed=16
I want to modify it with the variable energy.
If energy starts at 100, I want it to effectively make newspeed=16
But if energy is reduced by any means I want it to increase newspeed.

How can I accomplish this?
 
T

Thunder Lion

Guest
newspeed = swingspeed * (100 / energy);
I love you, being half awake has taken my brain to the lower depths of Norfair Mathematics. Works great! I will test it out in the actual project.
 
T

Thunder Lion

Guest
newspeed = swingspeed * (100 / energy);
How can I prevent a divide by zero apocalypse?? I was thinking of this: (100/(energy+1))
If energy is 0 then:
100/1
If energy is -1:
100/0....
Oh nooo
Hmmmmm....how to solve this?? Oh maybe I can have a preventive measure like if energy reaches 0 make energy equal one with that I don't need the +1
 

NightFrost

Member
Well you could ask yourself, does energy need to go into negatives? Does it need to go over 100 (or some other limit)? You can cap the value at both ends if there's no good reason for it to swing past those. For example 1 to 100. Or if you want it to be possible to go to zero, think what newspeed should be when energy is zero, and create a special case for that.
 
T

Thunder Lion

Guest
I did just that. My post stated one var but I'm combining 4 and it works great when my guys is low everything he acts like a sluggered but still can do work for gameplay sake. Thanks a bundle here take this.

(Ticket to see the bathroom)
 
Top