public float GetDistanceBeforeCollision(CreatureUtilities.RayCastDirection direction) { if (Time.time - _timeUpdatedDistanceToCollision[(int)direction] > .2f) { _RaycastDirection(direction); //Debug.LogWarning("Refreshing direction ray - " + direction); } return(distanceToCollision[(int)direction]); }
private void _RaycastDirection(CreatureUtilities.RayCastDirection direction) { Vector3 vectorDirection; if (direction == CreatureUtilities.RayCastDirection.FORWARD) { vectorDirection = _transform.forward; } else if (direction == CreatureUtilities.RayCastDirection.LEFT) { vectorDirection = -_transform.right; } else if (direction == CreatureUtilities.RayCastDirection.RIGHT) { vectorDirection = _transform.right; } else if (direction == CreatureUtilities.RayCastDirection.DOWN) { vectorDirection = Vector3.down; } else { Debug.LogError("Raycast direction for velocity in wrong method"); return; } RaycastHit hit; float rayLength = miscVariables[MiscVariables.AgentMiscVariables.Agent_Detect_Collision_Vel_Distance]; if (Physics.Raycast(_transform.position, vectorDirection, out hit, rayLength)) { if (DEBUG) { Color color; if (direction == CreatureUtilities.RayCastDirection.LEFT) { color = Color.white; } else if (direction == CreatureUtilities.RayCastDirection.RIGHT) { color = Color.red; } else { color = Color.yellow; } //Debug.DrawLine(_transform.position, hit.point, color, .5f); } distanceToCollision[(int)direction] = Vector3.Distance(_transform.position, hit.point); _timeUpdatedDistanceToCollision[(int)direction] = Time.time; } }