I am trying to make a shooter with a shotgun that is projectile based. However, at certain angles the spread changes from what it should be, im guessing due to the variation in transform. Forward. Is there anyway to fix these seemingly random offsets? `void ElementWeapons(int selection, int alternate) { float[] sgxoffsets = new float[8] {-0.025f,.025f,.025f,-.025f,.0175f,-.0175f,-.0175f,.0175f}; float[] sgyoffsets = new float[8] {-0.025f,-.025f,.025f,.025f,-.0175f,-.0175f, .0175f, .0175f }; float[] sgzoffsets = new float[8] { -0.025f, .025f, .025f, -.025f, .0175f, -.0175f, -.0175f, .0175f }; WeaponSwap WepSwap = transform.GetComponent();
switch (selection)
{
case 0: //Iron Shotugn Ferrous Fieldpiece
switch (alternate) {
case 0:
fireRate = 70;
if (firing == true)
{
ttf = Time.time + (1 / (fireRate / 60));
for (int i = 0; i < 8; i++)
{
toffset = new Vector3(sgxoffsets[i], sgyoffsets[i], sgzoffsets[i]);
var Vial = Instantiate(vial, transform.position, Cam.transform.rotation);
Vial.velocity = (90*(transform.forward +toffset));
Vial.GetComponent<VialBehavior>().vialElement = EleManager.instance.currentElement;
Vial.GetComponent<VialBehavior>().dmg = 2f;
}`
After Experimenting with Chuck's link, I looked at different options and found transform.TransformVector
, which created a constant spread see here:
for (int i = 0; i < 8; i++)
{
toffset = new Vector3(sgxoffsets[i], sgyoffsets[i], sgzoffsets[i]);
var Vial = Instantiate(vial, transform.position, Cam.transform.rotation);
Vial.velocity = (90*(transform.forward + transform.TransformVector(toffset)));
Vial.GetComponent<VialBehavior>().vialElement = EleManager.instance.currentElement;
Vial.GetComponent<VialBehavior>().dmg = 2f;
}