I’m using Unity 2D. Ok so I only want the raycast to go up from the game object, which I think it does but I only want it go to up in one direction however it seems like it goes out from the object in every direction, I did test and my character was far away from it and the object got destroyed which is only supposed to happen when you jump “over” it IE: hitting its raycast. The game object also gets destroyed from beneath which isn’t supposed it happen and it gets destroyed from various angles which also isn’t supposed to happen. And it also gets destroyed from any side no matter the distance it seems like it.
So to summarize what I want to happen: Only have the raycast go upwards vertically from the object (not in any other direction) and it only gets destroyed when hitting that raycast. I tried to change the numbers and even change vector 3 to vector 2 and vice-versa and I get the same result from the first paragraph. enter code here
RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, Vector3.up, 5);
if (hitInfo.collider.gameObject.tag == "Enemy")
{
Debug.DrawLine(transform.position, hitInfo.point, Color.white);
}
else
{
Debug.DrawLine(transform.position, Vector3.up * 5, Color.white);
Destroy(GameObject.FindWithTag("Enemy"));
}
}