Delta based multiplication

Monkey Forums/Monkey Programming/Delta based multiplication

Raz(Posted 2012) [#1]
Ok, I can't think of how to word this properly but here goes...

I have a delta float which determines how quickly the simulation moves. Usually it's set to 1.0, but sometimes I have it at 0.5 and 0.2.

[monkeycode]XS += XRate * delta[/monkeycode]

This is fine when adding to a value, but I would like to use it when multiplying a value (see the Else - End section), like so...

[monkeycode]If Input.LeftDown
XS -= XRate * delta
ElseIf Input.RightDown
XS += XRate * delta
Else
' Slowly decel the player
XS *= 0.99 * delta
End[/monkeycode]

Now obviously that line of code is wrong but I want to decrease XS using multiplication consistently regardless of delta.

I hope that makes some sense, can anyone help? I can't get my head round it!


Raz(Posted 2012) [#2]
Haha... err. Well I figured it out, quite soon after posting (even though it's been bothering me for a few days!)

[monkeycode]XS *= (1.0 - (0.01 * delta))[/monkeycode]


Xaron(Posted 2012) [#3]
Hey Chris, thanks for that.

Actually I never though of this I always did the "dampening" independently from the time period but your solution looks better!