How would I send a gameobject flying off in a random direction but make sure it has the same speed every time?
Before we apply any speed, we need a random direction. We can do this with the following:
Vector3 direction = new Vector3(Random.Range(-1f, 1f),
Random.Range(-1f, 1f),
Random.Range(-1f, 1f));
Now the problem with this is that if we scale it, it may not always scale to the proper velocity. We can fix this by making this a unit vector:
direction.Normalize();
Now that we have a unit vector in a random direction, we can fully scale it to a set speed:
Vector3 newVelocity = speed * direction;
Now, we apply it:
transform.GetComponent<Rigidbody>().velocity = newVelocity;
Ofcourse, you need to define speed to a float of your liking. Also, make sure your gameobject has a rigidbody attached to it.