/// <summary> /// Funzione che calcola lo spazio tra i raycast sia verticali che orrizontali /// </summary> private void CalculateRaySpacing(ColliderSettings _settings) { Bounds bounds = _settings.platformCollider.bounds; bounds.Expand(collisionOffset * -2); horizontalRayCount = Mathf.Clamp(horizontalRayCount, 2, int.MaxValue); verticalRayCount = Mathf.Clamp(verticalRayCount, 2, int.MaxValue); _settings.horizontalRaySpacing = bounds.size.y / (horizontalRayCount - 1); _settings.verticalRaySpacing = bounds.size.x / (verticalRayCount - 1); }
public void Init() { collidersSettings = new List <ColliderSettings>(); Collider[] platformColliders = GetComponentsInChildren <Collider>(); foreach (Collider c in platformColliders) { ColliderSettings newCollider = new ColliderSettings(); newCollider.platformCollider = c; CalculateRaySpacing(newCollider); UpdateRaycastOrigins(newCollider); collidersSettings.Add(newCollider); } }
/// <summary> /// Funzione che calcola i 4 punti principali da cui partono i raycast /// AltoDestra, AltoSinistra, BassoDestra, BassoSinistra /// </summary> private void UpdateRaycastOrigins(ColliderSettings _settings) { RaycastStartPoints raycastPoint; Bounds bounds = _settings.platformCollider.bounds; bounds.Expand(collisionOffset * -2); raycastPoint.bottomLeft = new GameObject("BottomLeftPoint").transform; raycastPoint.bottomRight = new GameObject("BottomRightPoint").transform; raycastPoint.topLeft = new GameObject("TopLeftPoint").transform; raycastPoint.topRight = new GameObject("TopRightPoint").transform; raycastPoint.bottomLeft.SetParent(transform); raycastPoint.bottomRight.SetParent(transform); raycastPoint.topLeft.SetParent(transform); raycastPoint.topRight.SetParent(transform); raycastPoint.bottomLeft.position = new Vector3(bounds.min.x, bounds.min.y, transform.position.z); raycastPoint.bottomRight.position = new Vector3(bounds.max.x, bounds.min.y, transform.position.z); raycastPoint.topLeft.position = new Vector3(bounds.min.x, bounds.max.y, transform.position.z); raycastPoint.topRight.position = new Vector3(bounds.max.x, bounds.max.y, transform.position.z); _settings.raycastPoints = raycastPoint; }