Is there an easy way to invert a number in C# with a function? I'm using XNA and i'd like to tell my program that if my 'variable' gets beyond a certain number it has to invert it's value. The whole point is to give a rebound effect.
if (ballPosition.X >= screenWidth)
{
// Invert the ball Direction Vector.X
}
The inverse of a number A is 1/A since A * 1/A = 1 (e.g. the inverse of 5 is 1/5) All real numbers other than 0 have an inverse. Multiplying a number by the inverse of A is equivalent to dividing by A (e.g. 10/5 is the same as 10* 1/5)
Reversing number in C means printing the given number back to the front. For example, the given number is 123, then the reverse of this number is 321.
Just whack a -
sign in front of it:
direction.X = -direction.X;
or you can try using Vector.X * -1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With