bool GetTurnToPosition(out Vec3 turnToPosition) { if (Instance != this) { Log.Fatal("PlayerIntellect: GetTurnToPosition: Instance != this."); } turnToPosition = Vec3.Zero; if (ControlledObject == null) { return(false); } //CutSceneManager specific if (CutSceneManager.Instance != null && CutSceneManager.Instance.CutSceneEnable) { return(false); } Vec3 from; Vec3 dir; if (!fpsCamera) { from = ControlledObject.Position + new Vec3(0, 0, tpsCameraCenterOffset); dir = lookDirection.GetVector(); } else { from = ControlledObject.Position + ControlledObject.Type.FPSCameraOffset * ControlledObject.Rotation; dir = lookDirection.GetVector(); } //invalid ray if (dir == Vec3.Zero || float.IsNaN(from.X) || float.IsNaN(dir.X)) { return(false); } float distance = 1000.0f; turnToPosition = from + dir * distance; RayCastResult[] piercingResult = PhysicsWorld.Instance.RayCastPiercing( new Ray(from, dir * distance), (int)ContactGroup.CastAll); foreach (RayCastResult result in piercingResult) { WaterPlane waterPlane = WaterPlane.GetWaterPlaneByBody(result.Shape.Body); if (waterPlane == null && result.Shape.ContactGroup == (int)ContactGroup.NoContact) { continue; } MapObject obj = MapSystemWorld.GetMapObjectByBody(result.Shape.Body); if (obj == ControlledObject) { continue; } if (waterPlane != null) { //ignore water from inside if (result.Shape.Body.GetGlobalBounds().IsContainsPoint(from)) { continue; } } Dynamic dynamic = obj as Dynamic; if (dynamic != null) { if (dynamic.GetParentUnitHavingIntellect() == ControlledObject) { continue; } } turnToPosition = result.Position; break; } return(true); }