Question by
trihugger · Jan 03, 2017 at 01:30 AM ·
physicsraycastraycasthitrayvector3.distance
RayCast(Ray ray, out RaycastHit hitInfo, float maxDistance, int layerMask) question
Hello,
I'm trying to use RayCast(Ray ray, out RaycastHit hitInfo, float maxDistance, int layerMask) to check for interception with the ground layer.
I have the ray initiated and distance calculated with:
Vector3 curPos = transform.position;
curPos.y += 0.5f;
RaycastHit hit;
Ray ray = new Ray(curPos, groundClips[i]);
float distance = Vector3.Distance(curPos, groundClips[i]);
Debug.DrawLine(curPos, groundClips[i], Color.grey);
if (Physics.Raycast(ray, out hit, distance, moveSettings.ground)){
return true;
}
The Drawline shows going right threw the ground layer, but yet that if statement returns false. Also the 0.5f adjustment was done simply as check to makes sure my origin(transform.position) was never below the ground layer.
Just for the record groundClips is an array of Vector3's pointing in different directions.
I don't have a problem when using the Physics.Raycast(Vector3 origin, Vector3 direction, float maxDistance, int layerMask), but not when you using the previous.
I'm sure there is something I'm missing.
Thank you,
Tri
Comment