- Home /
What did I wrong with my gun script???
I maded a Gun script but all my bullets don't hit somthing they just fly through everything. Can someone help me??
Here's the script:
var projectile : Rigidbody;
var speed = 20;
var shootsound : AudioClip; var shootanimation : AnimationClip;
function Update(){
if( Input.GetButtonDown( "Fire1" ) ) {
animation.Play("m4a1-shoot");
audio.PlayOneShot(shootsound); var instantiatedProjectile : Rigidbody = Instantiate( projectile, transform.position, transform.rotation );instantiatedProjectile.velocity = transform.TransformDirection( Vector3(
0, 0, speed ) );
} }
Please reformat your code properly, and include all of your code in the formatting- because you've left half of it out.
Answer by HolBol · Jun 20, 2012 at 10:27 AM
Are your bullets using colliders? If so, check the DontGoThroughThings script on the Unify Wiki. Another method for a shooting script would be using raycasts instead, and overlay some particle effects on top to make it seem that you are firing real particles. There are plenty of resources on this topic, have a look around.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Multiplayer FPS Fail 4 Answers
Dart/Bullet comes out pointing up 1 Answer
How do i make a fps where the gun always shoots realisticly 3 Answers
Bullet not moving 1 Answer