[SOLVED] Rotate vector by random max degree

Thanks for the tips everybody, I actually wanted the ability to have different random on different axis, I though maybe there’s a simple way to do it. Anyway ended up doing something like this:

    /// <summary>
    /// Random vector direction.
    /// </summary>
    protected Vector3 RandDirection(Vector3 baseVector, Vector3 randDir)
    {
        float originalLen = baseVector.Length();
        Vector3 newVelocity = baseVector;
        newVelocity.X += (float)(Random.NextDouble() * randDir.X - Random.NextDouble() * randDir.X);
        newVelocity.Y += (float)(Random.NextDouble() * randDir.Y - Random.NextDouble() * randDir.Y);
        newVelocity.Z += (float)(Random.NextDouble() * randDir.Z - Random.NextDouble() * randDir.Z);
        newVelocity.Normalize();
        return newVelocity * originalLen;
    }

Which appears to be working pretty well for now… :slight_smile:

2 Likes