Reputation: 13283
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
}
Upvotes: 14
Views: 30529
Reputation: 32576
Just whack a -
sign in front of it:
direction.X = -direction.X;
Upvotes: 45