Question by
Equ1l1brist · Jan 12, 2017 at 05:04 PM ·
raycastoncollisionenter
Raycast to detect point on adjacent wall
I have two planes placed horizontally like walls (mesh renderer has been removed). And want a ray to be cast when the player collides with one, which should shoot forward to detect a point on the other plane/wall. The problem is I can't detect the hit.point from the other wall. Here's my code:
//Shoot ray forward from player's point of contact - poc passed in
//And find hitpoint on adjacent telewall
public Vector3 TeleportRay()
{
Vector3 _telePoint = Vector3.zero;
RaycastHit _hit;
Ray _ray = new Ray(poc, transform.up * -1 * rayLength);
Debug.DrawRay(poc, transform.up * -1 * rayLength, Color.red, Mathf.Infinity);
if (Physics.Raycast(_ray, out _hit)) {
if (_hit.collider.tag == "TeleWall") {
print("Hit "+_hit.point);
}
}
return _telePoint;
}
Comment
Your answer
Follow this Question
Related Questions
Can you raycast to detect a point on the other side of a cube 0 Answers
Check if position is inside a collider 5 Answers
onMouseUp 2D Issues 0 Answers