Get Direction From Raycast
Hi,
I'm not entirely sure how to explain it in the title, but heres what I need to do:
I have a plane in a scene. I fire a raycast at the plane in any of its space. I need to know whether the raycast hit forward, backward, left or right from the center of the plane. I've treid rounding the eulerAngles from the Vector3.Angle() calculation but it just doesn't work.
Heres the code I'm using:
private void Update()
{
if (controllerUtils.GetTriggerDown())
{
RaycastHit hitInfo;
BuildDirection direction;
if (!Physics.Raycast(buildingHand.position, buildingHand.forward, out hitInfo))
{
Debug.Log("Hit nothing");
return;
}
float ddirection = Mathf.Round(Vector3.Angle(hitInfo.collider.gameObject.transform.forward, hitInfo.collider.gameObject.transform.position - hitInfo.point) / 90) * 90;
Debug.Log(ddirection);
}
}
Thanks, Ethan.
edit: sorry for the bad code and variable names. its not this bad in my project, but it wouldn't make sense to have a carbon copy in this question.
Your answer
Follow this Question
Related Questions
Plane is blocked all Raycast 0 Answers
Pseudo 3D like in Wolfenstein 3D 1 Answer
Camera Follow Script destroys Raycast on VR-Hands with Late Update 1 Answer
[SOLVED] get object which is nearby to mouse 1 Answer
Can't get raycast to mousePosition 0 Answers