Hello, i have a bullet where when i shoot a bullet and move the ship the bullet shootsforwards but follows on the ship Position to left an right.
Here my scripts:
public class Bullet : MonoBehaviour
{
public Rigidbody2D Rigidbody;
public float Speed;
public int Damage;
public GameObject ExplosionPrefab;
private void Start()
{
Rigidbody.GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
Rigidbody.AddRelativeForce(Vector2.up * Speed);
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Enemy"))
{
var meteoroidController = collision.GetComponent<MeteoridController>();
meteoroidController.TakeDamage(Damage);
Instantiate(ExplosionPrefab, transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
}
public class WeaponSystem : MonoBehaviour
{
public Transform Spawnpoints;
public Bullet BulletPrefab;
public float FireRate = 1;
public AudioSource SoundEffect;
private float _fireRatecounter;
private void Update()
{
_fireRatecounter += Time.deltaTime;
}
public void Fire()
{
if (_fireRatecounter >= FireRate)
{
_fireRatecounter = 0;
SoundEffect.Play();
foreach (var spawnPoint in Spawnpoints)
{
Instantiate(BulletPrefab, spawnPoint);
}
}
}
}
thanks for the help