void FeedBack() { if (boundSpheres != null) { // 遍历自身所有碰撞球,若与外物有碰撞,则计算“力”反馈后的位置 for (int i = 0; i < boundSpheres.Length; ++i) { BoundSphere sphere = boundSpheres[i]; if (sphere == null) { continue; } foreach (Collider collider in Physics.OverlapSphere(OffsetPosition(sphere.offset), sphere.radius, _collidable)) { Vector3 position = OffsetPosition(sphere.offset); Vector3 contactPoint = Vector3.zero; if (collider.gameObject == _target.gameObject) { continue; // 排除自身 } if (collider.isTrigger) { continue; } if (collider is BoxCollider) { contactPoint = TransformTools.Instance.ClosestPoint((BoxCollider)collider, position); } else if (collider is SphereCollider) { contactPoint = TransformTools.Instance.ClosestPoint((SphereCollider)collider, position); } else if (collider is MeshCollider) { TriangleTreeMgr ttm = collider.GetComponent <TriangleTreeMgr>(); if (ttm == null) { ttm = collider.gameObject.AddComponent <TriangleTreeMgr>(); } if (ttm != null) { contactPoint = ttm.ClosestPointOn(position, sphere.radius, displayDebugInfo, displayExtendedDebugInfo); } else { // Make last ditch try for convex colliders MeshCollider mc = (MeshCollider)collider; if (mc.convex) { contactPoint = mc.ClosestPointOnBounds(position); } else { continue; } } } else if (collider is CapsuleCollider) { contactPoint = TransformTools.Instance.ClosestPoint((CapsuleCollider)collider, position); } else if (collider is TerrainCollider) { // 无须处理,地面和foot的碰撞检测在其它模块 } else if (collider is WheelCollider) { Debug.LogWarning("[Moter] WheelColliders not supported"); } else { continue; } if (contactPoint != Vector3.zero) { // If the sphere is feet // We have a ground and we're touching // And the sphere position is above the contact position // We should ignore it if (sphere.isFeet && IsOnGround && position.y > contactPoint.y) { continue; } // If this is the head sphere // And we're jumping // And we hit the "top" of the sphere, abort jumping if (sphere.isHead && IsJumping && contactPoint.y > (position.y + sphere.radius * 0.25f)) { JumpDone(null); } // Vector from contact point to position Vector3 v = position - contactPoint; // Draw debug line if (displayDebugInfo) { Debug.DrawLine(position, contactPoint, Color.red); } // Display extend debug info if (displayExtendedDebugInfo) { Debug.Log("[Moter] Contact point " + contactPoint); } // Move object away from collision _target.position += Vector3.ClampMagnitude(v, Mathf.Clamp(sphere.radius - v.magnitude, 0, sphere.radius)); } } } } }
public void UpdateBound() { boundcache = null; }
public virtual void DrawShadowVolume(BoundSphere Light, ShaderMaterial ShadowVolume) { }