I’m working on destroying a bullet 3 seconds after it’s created, and making the bullet appear at the same position of the barrel. The bullet is created, has the same rotation, and accelerates. It just goes up and to the right of where the barrel actually is. Also, for some reason, I can’t seem to destroy the projectile, which is a rigidbody. Can anybody help?
function Fire() {
var projectile = Instantiate(bullet, barrel.position, barrel.rotation);
projectile.rigidbody.AddForce(transform.forward * speed);
bullets++;
Destroy(transform, 3);
}
What object is this script on? You’re adding force in the direction of the object this script is running on. Is that what you’re trying to do? I’m not clear on what exactly you’re trying to achieve.