- Home /
Shooting length
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.
Answer by ExTheSea · Apr 09, 2012 at 10:42 PM
you had to uncheck the Use Gravitiy Checkbox under the rigidbody sector of your fireball gameobject/prefab.
hope this helped
Fml, no idea how I overlooked that! I absolutely forgot about this. Siiigh. Huge flop on my behalf.
Thanks!
Your answer
Follow this Question
Related Questions
Enemy not getting hit (Collider issue) 2 Answers
[SOLVED] Shooting fail (Due to camera setup) 2 Answers
Can someone help me with my script? 0 Answers
Wait for reload to finish? 1 Answer