public float speed = 15f;
Vector2 Dir;
Vector2 NDir;
private void Start()
{
Dir = transform.right;
NDir = Dir;
}
private void Update()
{
Rigidbody2D rb = GetComponent();
if (rb != null)
rb.velocity = NDir * speed;
}
private void OnCollisionEnter2D(Collision2D other)
{
if (other.collider.CompareTag(“Objects”))
{
NDir = Vector2.Reflect(Dir, other.contacts[0].normal);
}
}
the projectile hits the wall, then it reflects, but when it hits again it does not reflect