- Home /
Question by
recaigeciken14 · Mar 14, 2021 at 11:56 AM ·
collider2dtransform.positionrayraycasthit2d
RaycastHit2D hits the objects from start point of Raycast
Im making a raycast beam from transform.position to tag("Npc").position and the hit process works just in start of raycast beam point.
For example in the image i uploaded, raycast beam hit the npc just from black circle point not the red circle point.
checkforpos = Vector2.zero;
if (gameObject.GetComponent<movement>().raycastbeampoisiton == 1)
{
checkforpos = Vector2.left;
}
if (gameObject.GetComponent<movement>().raycastbeampoisiton == 2)
{
checkforpos = Vector2.right;
}
Debug.DrawRay(transform.position, checkforpos * 10f);
if (Input.GetMouseButton(0))
{
RaycastHit2D hitINFO = Physics2D.Raycast(transform.position, checkforpos, 10f);
if (hitINFO.collider != null && hitINFO.collider.tag == "NPC")
{
Debug.Log("hitted");
}
}
adsız.png
(13.8 kB)
Comment
I just want to make the ray beam hit from the rays ending point.(Ending point is the red circle in image)
Your answer
![](https://koobas.hobune.stream/wayback/20220613030650im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How come people prefer to use rays for 2d collision instead of edge colliders? 1 Answer
Issue with Raycasts in Unity 2D 2 Answers
How can i shoot 2D ball/bounce of wall using Raycast? 1 Answer
Is my 2D Raycast set up correctly? because it does not seem to hit anything when i use a layer mask. 1 Answer