- Home /
shooting straight
ok i have a script which makes my bullets shoot using a rigid body but when it shoots the bullet goes in kind of a rainbow pattern. its hard to explain but the bullet goes in kind of a loop instead of going in a straight line . any way to fix this? here is my code ( from fps tutorial)
// from fps tutorial
var projectile : Rigidbody; var initialSpeed = 20.0; var reloadTime = 0.5; var ammoCount = 20; private var lastShot = -10.0; var sound : AudioSource; var r : AudioClip;
function Fire () { // Did the time exceed the reload time? if (Time.time > reloadTime + lastShot && ammoCount > 0) { // create a new projectile, use the same position and rotation as the Launcher. var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);
// Give it an initial forward velocity. The direction is along the z-axis of the missile launcher's transform.
instantiatedProjectile.velocity = transform.TransformDirection(Vector3(0, 0, initialSpeed));
sound.PlayOneShot(r);
// Ignore collisions between the missile and the character controller
Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
lastShot = Time.time;
ammoCount--;
}
}
can anyone tell me how to fix this to make my character shoot directly straight
Answer by Mike 3 · Jun 25, 2010 at 11:49 PM
The code there looks perfectly fine - sure there isn't anything on the projectile affecting it?