To further clarify, right now all of my bullets are shooting perfectly straight using:

``````        theRB.velocity = transform.right * speed;
``````

Here’s what that looks like now:

How can I add some variance so that my bullet isn’t firing perfectly straight, but rather has a cone of bullet spread?

Thanks!

transform.right is vector, so it can’t be rotated it will always be right of your local space object.

``````Vector3 direction  = Quaternion.Euler(0, yourDirection, 0) *  transform.forward;
``````

Sorry, I’m a bit of a n00b. This code, can you elaborate on it a little? Where does direction belong?

You can use something like Random.InsideUnitCircle or Random.InsideUnitSphere to get a random vector and then multiply your output by that. I’d also recommend having a variable you can use to change the scale of that vector (so you can have weapons with more extreme spreads like a shotgun for example). Are you doing 2D or 3D?

This is 2D, top down (there’s an Instagram link of the video in the og post).

I’m not sure how InsideUnitSphere/Circle applies to my situation? Can you explain a little?

So when you’re making it aim towards the mouse I assume you’re just doing a MoveTowards or LookAt or something to that effect, right? Just add the result of the UnitCircle multiplied by a scale/spread float (so your target position would be something like `mousePosition + (unitCircle * scale)`).

transform.right + new vector(0,random.range(1,-1),0) *speed;

Actually what I am doing is rotating the parent gameObject so that transform.right send the bullet flying in whatever direction the “firepoint” is.

I’d really like to retain the transform.right part of this equation, but I don’t want it to be strictly right. I’d like for “right” to have some variance.

Just bumping this - still don’t have a solution for adding variability to transform.right

A simple way is to make the bullet object rotate upon creation. For example:

``````public class Gun : MonoBehaviour {

void Shoot() {
GameObject bullet = /*However you get your bullet objects*/