- Home /
My bullets arent going the right direction
I have a code here to make a bullet shoot but for some reason as a turn the bullet shoots in the direction i came from, here is the code
var bullet : Rigidbody; //Your bullet prefab. Should have a RigidBody var speed : float = 10.0f; var muzzlePoint : Transform; //Your SpawnPoint var GunShot : AudioClip;
function Update() { if(Input.GetButtonDown("Fire1")) { var instance : Rigidbody = Instantiate(bullet, muzzlePoint.position, muzzlePoint.rotation); instance.velocity = muzzlePoint.forward * speed; audio. PlayOneShot (GunShot); } }
please help
Answer by fafase · Nov 29, 2012 at 08:52 AM
You have a rigidbody there you should use the rigidbody function like AddForce:
var bullet : Rigidbody;
var speed : float = 10.0f;
var muzzlePoint : Transform;
var GunShot : AudioClip;
var shoot:boolean =false;
function Update() {
if(Input.GetButtonDown("Fire1")){
shoot =true;
audio.PlayOneShot(Gunshot,0.7f);
}
}
function FixedUpdate(){
if(shoot){
var instance : Rigidbody = Instantiate(bullet, muzzlePoint.position, muzzlePoint.rotation);
instance.rigidbody.AddForce(transform.forward*speed);
shoot =false;
}
}
You might want to give more speed as well
Your answer
Follow this Question
Related Questions
Asteroids moving in the wrong direction 2 Answers
For gameobject different ray, logic problem 0 Answers
Entity moving along the wrong axis 0 Answers
what is going on with shadows on my mesh? 2 Answers
Model is facing the wrong way 1 Answer