- Home /
Bullets. Rotation Probelm
when i fire a bullet, its projection is great. The only problem i am facing is that bullet's position is not accurate. it should be pointy but it's position is horizontal. i have tried to change the position and rotation of its prefab but still the same problem. Kindly help me. Following are my 2 scripts, 1st one is projection for gun and 2nd one is for bullet's reaction
// This script is used to for projection of a fire
pragma strict
var projectile : GameObject; var fireRate : float = 0.5; internal var nextFire :float; var speed : float = 20; var weaponFireFX : AudioClip;
function Start () {
}
function Update () { // fire1 button is left mouse button if (Input.GetButton ("Fire1") && Time.time > nextFire) { nextFire = Time.time + fireRate; var clone : GameObject = Instantiate (projectile, transform.position, transform.rotation); clone.rigidbody.velocity = transform.TransformDirection(Vector3 (0,0,speed)); Physics.IgnoreCollision(clone.collider, transform.root.collider); audio.PlayOneShot(weaponFireFX);
} }
// This script is used in bullet to collide with terrain or any other object
pragma strict
var hitSound : AudioClip; var explosion : GameObject;
function Start () { Destroy (gameObject, 5); }
function Update () {
}
function OnCollisionEnter (collision : Collision) { //get the first hit point's location var contact : ContactPoint = collision.contacts[0]; // gets the hit face's normal's direction/rotation var rotation = Quaternion.FromToRotation(Vector3.up,contact.normal);
if (collision.transform.tag != "Don't Destroy")
{
//send message to hit object for damage
collision.transform.SendMessage("BeenHit",SendMessageOptions.DontRequireReceiver);
var theExplosion : GameObject = Instantiate(explosion, contact.point, rotation);
audio.PlayOneShot(hitSound);
yield;
Destroy (gameObject,1);
}
else
{
Destroy (rigidbody,5);
//print ("stopped " + collision.transform.name);
}
}
Your answer