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.