public override Goal Suggest(LineSegmentPath path, KinematicData character, Goal goal) { // procurar ponto do segmento mais próximo ao centro da esfera Vector3 closest = path.GetPosition(MathHelper.closestParamInLineSegmentToPoint(path.StartPosition, path.EndPosition, center)); // Check if we pass through the center point Vector3 newPt; if (closest.sqrMagnitude == 0) { // Get any vector at right angles to the segment Vector3 dirn = path.EndPosition - path.StartPosition; //pode nao ser esta func TO DO Vector3 newdirn = Vector3.Cross(dirn, Vector3.Cross(dirn, Vector3.right)); newPt = center + newdirn * radius * margin; } else { // Otherwise project the point out beyond the radius newPt = center + (closest - center) * radius * margin / closest.sqrMagnitude; } // Set up the goal and return goal.position = newPt; return(goal); }
public override Boolean WillViolate(LineSegmentPath path) { Vector3 impactPoint = path.GetPosition(MathHelper.closestParamInLineSegmentToPoint(path.StartPosition, path.EndPosition, Troll.KinematicData.position)); Vector3 direction = Troll.KinematicData.position - impactPoint; float distance = Vector3.Magnitude(direction); if (distance < TrollRadius) { // Debug.Log("VIOLATE!"); return(true); } // Debug.Log("NO VIOLATE!"); return(false); }