hi. im new to unity. i am creating a simple shooting game. I am using the unity code for a first person shooter (below), but want to know how i can change the speed of the bullet, and how to “turn off gravity”.
About the speed of the bullet when it is shot, that’s what the speed variable is for. While it’s on air though, you’ll need a reference on that bullet and do bullet.rigidbody.velocity *= something;
You can set instantiatedProjectile.useGravity to false to disable gravity. About the projectile speed, it’s defined by the variable speed, as @Berenger said. Once fired, the projectile keeps its velocity constant for the eternity (unless gravity is enabled or Drag isn’t zero).
var projectile : Rigidbody;
var speed = 20; // this sets the speed in meters/second
function Update()
{
if( Input.GetButtonDown( "Fire1" ) )
{
var instantiatedProjectile : Rigidbody = Instantiate(
projectile, transform.position, transform.rotation );
instantiatedProjectil.useGravity = false; // disable gravity
// set the bullet speed:
instantiatedProjectile.velocity = transform.TransformDirection( Vector3( 0, 0, speed ) );
Physics.IgnoreCollision( instantiatedProjectile. collider,
transform.root.collider );
}
}