Im making a simple top down shooter, but
when I fire and rotate the player, my bullet follows my player rotation.
I think it looks cool but I want it to go in a straigh line. I have no idea how to fix this. Please help.
Here’s my bullet script
public GameObject go;
private Rigidbody2D bRB;
public float bulletLifespan;
public float bulletLifespanReset;
public float bulletSpeed;
void Start()
{
bRB = GetComponent<Rigidbody2D>();
go = GameObject.Find("BulletSpawner");
}
// Update is called once per frame
void Update()
{
BulletMvm();
Despawn();
}
void BulletMvm()
{
Transform goTransform = go.GetComponent<Transform>();
transform.Translate(goTransform.transform.right * bulletSpeed * Time.deltaTime);
}
Here’s where i spawn my bullet
public class BulletSpawner : MonoBehaviour
{
public GameObject bulletPrefab;
public Transform spawnPoint;
//public NormalBullet s_NB;
public float timer;
public float fireRate;
// Update is called once per frame
void Update()
{
ActiveShoot();
}
public void ActiveShoot()
{
if (timer <= 0.0f)
{
Shoot();
timer = fireRate;
}
timer -= Time.deltaTime;
}
public void Shoot()
{
float x = spawnPoint.position.x;
float y = spawnPoint.position.y;
Vector2 sP = new Vector2(x, y);
ObjectPooler.Spawn(bulletPrefab, sP, Quaternion.identity);
}
}