How to add random force/Rotation to bulletEject.

var bulletshell = Instantiate(bulletPrefab,shellSpawn.position, shellSpawn.rotation);
bulletshell.rigidbody.AddForce(transform.up + transform.right * 60);
bulletPrefab.transform.rotation * Quaternion.Euler(Random.Range(-10,10),0,0);

is where i instantiate it. i tryed Random.rotation but that is really ugly… But i can’t figure out how to add random rotation/force so when the bullet is instantiated it looks more realistic, Does someone know how to make this work :slight_smile:

Add a ConstantForce component to your bullet shell prefab, then add a script to that prefab. In that script, set the torque of the constant force to be random like so:

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour
{
	Vector3 torque;
	
	void Awake()
	{
		torque.x = Random.Range (-200, 200);
		torque.y = Random.Range (-200, 200);
		torque.z = Random.Range (-200, 200);
		constantForce.torque = torque;
	}
}

Have a look here for more info on constantForce.torque.

EDIT: If you want to do this in JS instead of C#

var torque : Vector3;

function Awake()
{
	torque.x = Random.Range (-200, 200);
	torque.y = Random.Range (-200, 200);
	torque.z = Random.Range (-200, 200);
	constantForce.torque = torque;
}