I am trying to fire a rigid body forward, here is my code:
Instantiating the ‘bullet’:
ExplosiveBulletb = ObjectPoolManager.CreatePooled(bulletPrefab.gameObject, _bulletSpawn.position, _bulletSpawn.rotation * accuracySeed).GetComponent<BulletBase>() as ExplosiveBullet;
And here is the script I have attached to my bullet prefab (simple sphere object with a box collider, nothing special)
using UnityEngine;
using System.Collections;
public class ExplosiveBullet: MonoBehaviour {
public float speed = 10.0F;
public float lifeTime = 2.0F;
protected Transform _tr;
protected float _spawnTime = 0.0F;
public virtual void Start() {
_tr = transform;
_spawnTime = Time.time;
rigidbody.AddForce(_tr.forward * speed, ForceMode.Impulse);
}
void Update() {
if (Time.time > _spawnTime + lifeTime){
DestroyBullet();
return;
}
}
void Explode(){
Debug.Log("Booom!");
}
void OnCollisionEnter(Collision c){
Explode();
DestroyBullet();
}
public void DestroyBullet(){
ObjectPoolManager.DestroyPooled( gameObject );
gameObject.SetActiveRecursively(false);
}
}
For some reason, my bullet never seems to fire forward. It shoots off in strange directions which don’t seem very relevant to my players facing. Any ideas?