I basically want to check if newValue goes past targetValue. But targetValue could be either a positive or negative number, so if ( newValue < targetValue )
won't necessarily work.
I coded it the way below, and I may be overthinking things here but I wondered if there's a way to rewrite the if-check a bit more elegantly…</p>
var newValue = 0;
function ChangeValue ( targetValue : int )
{
var isTargetPositive = ( targetValue > 0 );
if ( isTargetPositive && newValue < targetValue || !isTargetPositive && newValue > targetValue )
newValue = math.moveTowards( newValue, targetValue, 1 );
else
// Do something else
}