A question regarding projectiles

I am currently trying to develop a 2D TopDown-style game, and I am working towards having projectiles implemented. However, a problem that I seem to have is that whenever projectiles collide with the player, they do destroy themselves, however the player just continues with the velocity of the projectile.

The code for the projectile is as follows

`using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Object = UnityEngine.Object;

public class Arrow : MonoBehaviour
{
// Start is called before the first frame update
public float speed = 20.0f;
public Rigidbody2D rb;
public int damage = 40;
private GameObject arrow;
private GameObject arrowTrap;
private basicPlayer player;
void Start()
{
rb.velocity = transform.right * speed;
arrow = this.gameObject;
player = new basicPlayer();
Physics2D.IgnoreCollision(this.GetComponent(), arrowTrap.GetComponent());
}

// Update is called once per frame
void Update()
{
    
}

private void OnCollisionEnter2D(Collision2D collision)
{
    if (collision.gameObject.CompareTag("player")) {
        collision.gameObject.GetComponent<basicPlayer>().UpdateHealth(damage);
        Object.Destroy(this.gameObject);
    }
    
}

}
`

Is there anything I’m missing here? Is there something I need to check with my object properties? As this issue has been troubling me for a while now.

Hi @AlphaTails, If you are dealing with rigidbody objects, then when one object collides with another it will impart at least some of it’s velocity on the other object, depending on the rigidbody properties you’ve set.

What do you want to have happen - the player to not move at all then they get hit?

An easy way would be to set the bullet then as a trigger ( Is Trigger checked, or set to true in your code) and check for OnTriggerEnter instead of OnCollisionEnter - just move your same code into that instead.

You’d only have problems with this if you want your projectiles to bounce of other objects.

As a bonus, you would not need the IgnoreCollision code either.