Why does this rigidbody not fire forwards?

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?

1 Answer

1

the problem of shooting to a wrong direction is usually caused by wrong direction of the z axis (transform.forward). So check ur axis of spawn point for bullet (if u hav) or check other gameobjects which are related to the instantiate of the bullet!!! Hope this help