- Home /
Question by
hbeing427 · May 01, 2020 at 01:54 PM ·
raycastunity 2dphysics2draycasthit2d
How to get co-ordinates of end point of Raycast2D ?
I m working on the simple 2D game project and it have building system like you can place walls, platforms, etc. I m using RaycastHit2D to detect collision, but the problem is that if the raycast doesn't hit anything on its way then how to get the end point of the ray?
using UnityEngine;
public class PlayerController : MonoBehaviour
{
Private float distance = 2.4f;
Private Vector2 endPoint;
private void FixedUpdate(){
RaycastHit2D hit = Physics2D.Raycast(transform.position,
Vector2.right, distance);
if(hit.collider == null){
//how to get the end point co-ordinate of the ray?
}
}
}
Comment
Answer by Priyanka-Rajwanshi · May 01, 2020 at 02:55 PM
Oh i made a mistake while writing code... there should be
if(hit.collider == null){ ////// }
i corrected it, now how can i do that ? if it doesn't hid any colliders but still wants the end point of the ray after it travelled given distance