Hi guys and girl.
Im blaying around with bullet spread and cant quite get the desired result.
When the player fires i want one bullet to go streight and the bullet on the left angle out from the spawn position, the same goes for the right bullet.
Its a 2d to down shooter.
¨
Ive got the bullet script to work fine, and the bullet fires at the mouse position but all 3 bullets go streight!?
any idears?
Thanks in advance.
Here is a rough image of what im trying to do.

rotate the bullets as you want as you instantiate them then use
transform.position += transform.position.forward * movementSpeed * time.deltaTime;
to move them
Dont think that will work in my case. here is the Bullet script
var myPos = transform.position + Vector3(0.0,1.0,0.0);
var dist = Camera.main.transform.position.y-myPos.y;
var x = Input.mousePosition.x;
var y = Input.mousePosition.y;
var dir = Camera.main.ScreenToWorldPoint(Vector3(x, y, dist))-myPos;
var BulletClone = Instantiate(bullet, myPos, Quaternion.LookRotation(dir));
BulletClone.rigidbody.velocity = dir.normalized * BulletSpeed;
Physics.IgnoreCollision(BulletClone.collider, collider);
Destroy(BulletClone,2);
If i rotate the bullet to lets say 15 degrees it will still fly in a streight line.
Its a top down shooter so the player can shoot 360 degrees at the mouse point
change to
BulletClone.rigidbody.velocity = BulletClone.transform.forward * BulletSpeed;
make sure you rotate the clone before using this line.
Build a bullet prefab with 3 bullets. (I would do like 10 and make them in a spread, facing the desired directions)
Attach them to the front of your gun and make them face in the “shooting” direction, then make them inactive.
Create a script that references the bullet prefab at the front of the gun.
Instantiate them at the position and rotation of the bullet prefab.
make them active.
for added realism, change the localEulerAngles.z to Random.value * 360
In your script, cycle through each child of the bullet spread and set the velocity individually.
Thanks guys for the input
now it works like a charm.
With the same bullet prefab
var myPos = transform.position + Vector3(0.0,50.0,0.0);
var myPosLeft = transform.position + Vector3(0.0,76.0,0.0);
var myPosRight = transform.position + Vector3(0.0,112.0,0.0);
var dist = Camera.main.transform.position.y-myPos.y;
var x = Input.mousePosition.x;
var y = Input.mousePosition.y;
var dir = Camera.main.ScreenToWorldPoint(Vector3(x, y, dist))-myPos;
var BulletClone = Instantiate(bullet, myPos, Quaternion.LookRotation(dir));
//BulletClone.transform.Rotate(0.0, randomNumberY, 0.0);
BulletClone.rigidbody.velocity = BulletClone.transform.forward * BulletSpeed;
Physics.IgnoreCollision(BulletClone.collider, collider);
Destroy(BulletClone,1);
var BulletCloneLeft = Instantiate(bullet, myPosLeft, Quaternion.LookRotation(dir));
BulletCloneLeft.transform.Rotate(0.0, -strayFactor, 0.0);
BulletCloneLeft.rigidbody.velocity = BulletCloneLeft.transform.forward * BulletSpeed;
Physics.IgnoreCollision(BulletCloneLeft.collider, BulletClone.collider);
Destroy(BulletCloneLeft,1);
var BulletCloneRight = Instantiate(bullet, myPosRight, Quaternion.LookRotation(dir));
BulletCloneRight.transform.Rotate(0.0, strayFactor, 0.0);
BulletCloneRight.rigidbody.velocity = BulletCloneRight.transform.forward * BulletSpeed;
Physics.IgnoreCollision(BulletCloneRight.collider, BulletClone.collider);
Destroy(BulletCloneRight,1);