var projectile : Transform;
var bulletSpeed : float = 100;
function Update ()
{
// Put this in your update function
if (Input.GetMouseButtonDown(0)) {
// Instantiate the projectile at the position and rotation of this transform
var clone : Transform;
clone = Instantiate(projectile, GameObject.Find("spawnPoint").transform.position, transform.rotation);
// Add force to the cloned object in the object's forward direction
clone.rigidbody.AddForce(clone.transform.forward * 1000);
}
Destroy(clone.gameObject, 5);
}
Okay, so what this code does is generates a clone of my fireball (projectile) when the user has clicked on the LMB. However when it instantiates, it goes forward by 10m and then falls to the ground. How do I make it so that when it’s created it goes in a straight line (like a raycast). I’ve set it to destroy after 5 seconds so it should disappear in the air.
So the real question is, how do I make it stay in the air?
Look forward to your answers.