I want to be able to choose a random angle (between 0 and 360 or 0 and 2pi) and then have a sprite move in that direction. So far I have tried this, but it has been pretty noneffective, as it always moves down, and the angle choosing isn’t very pretty.
Random rand = new Random();
//Chooses the Angle
rotation = (float)rand.NextDouble()*MathHelper.TwoPi;
//Is supposed to get a normalized movement vector that moves in the direction of that angle.
moveVector = Vector2.Normalize(new Vector2(-(float)Math.Tan(rotation), 1));
You seem to be missing a dab of trigonometry:
You’re creating a vector with a Y component that’s always 1 (down in 2D XNA). So, no matter the random angle, it only affects the horizontal part of the direction.
To turn an angle into a (unit, i.e. already-normalized) directional vector, you can use sin and cos (think of the unit circle):
Since XNA puts the origin at the top-left of the screen for 2D, you need to reverse the y-component:
Additionally, to ensure you get a proper sequence of random numbers, you should only create the random object once, then use the same instance every time to get the next random number.
Also, to get smoother motion, you can either weight the direction in favour of the direction you’re already going in, or pick a random destination and travel to that (then pick another one, etc.).