protected VInt3 CalculateTargetPoint(VInt3 p, VInt3 a, VInt3 b) { if (a.x == b.x && a.z == b.z) { return(a); } VFactor f = AstarMath.NearestPointFactorXZ(ref a, ref b, ref p); long a2 = VInt3.Lerp(a, b, f).XZSqrMagnitude(ref p); int num = IntMath.Sqrt(a2); long a3 = a.XZSqrMagnitude(ref b); int num2 = IntMath.Sqrt(a3); if (num2 == 0) { return(b); } int num3 = Mathf.Clamp(this.forwardLook.i - num, 0, this.forwardLook.i); VFactor vFactor = new VFactor((long)num3 * f.den + f.nom * (long)num2, (long)num2 * f.den); if (vFactor > VFactor.one) { vFactor = VFactor.one; } else if (vFactor < VFactor.zero) { vFactor = VFactor.zero; } vFactor.strip(); return(VInt3.Lerp(a, b, vFactor)); }
public void Normalize() { long num = this.x * 100; long num2 = this.y * 100; long a = (num * num) + (num2 * num2); if (a != 0) { long b = IntMath.Sqrt(a); this.x = (int)IntMath.Divide((long)(num * 0x3e8L), b); this.y = (int)IntMath.Divide((long)(num2 * 0x3e8L), b); } }
private long QueryRec(int i, Int2 p, long radius, Agent agent, VRect r) { if (this.nodes[i].child00 == i) { for (Agent agent2 = this.nodes[i].linkedList; agent2 != null; agent2 = agent2.next) { long a = agent.InsertAgentNeighbour(agent2, radius * radius); if (a < (radius * radius)) { radius = IntMath.Sqrt(a); } } return(radius); } Int2 center = r.center; if ((p.x - radius) < center.x) { if ((p.y - radius) < center.y) { radius = this.QueryRec(this.nodes[i].child00, p, radius, agent, VRect.MinMaxRect(r.xMin, r.yMin, center.x, center.y)); } if ((p.y + radius) > center.y) { radius = this.QueryRec(this.nodes[i].child01, p, radius, agent, VRect.MinMaxRect(r.xMin, center.y, center.x, r.yMax)); } } if ((p.x + radius) > center.x) { if ((p.y - radius) < center.y) { radius = this.QueryRec(this.nodes[i].child10, p, radius, agent, VRect.MinMaxRect(center.x, r.yMin, r.xMax, center.y)); } if ((p.y + radius) > center.y) { radius = this.QueryRec(this.nodes[i].child11, p, radius, agent, VRect.MinMaxRect(center.x, center.y, r.xMax, r.yMax)); } } return(radius); }
public void Enter(Action _action) { this.skillContext = _action.refParams.GetRefParamObject <SkillUseContext>("SkillContext"); this.lastTime = 0; this.lastVelocity = (this.lastLerpVelocity = this.velocity); this.stopCondtion = false; this.moveActor = _action.GetActorHandle(this.targetId); if (!this.moveActor) { return; } this.gravityControler = new AccelerateMotionControler(); this.moveActor.get_handle().ObjLinker.AddCustomMoveLerp(new CustomMoveLerpFunc(this.ActionMoveLerp)); if (this.MoveType == ActorMoveType.Target) { this.tarActor = _action.GetActorHandle(this.destId); if (!this.tarActor) { return; } this.destPosition = this.tarActor.get_handle().location; CActorInfo charInfo = this.tarActor.get_handle().CharInfo; if (charInfo != null) { this.hitHeight = charInfo.iBulletHeight; VInt3 vInt = this.moveActor.get_handle().location - this.destPosition; vInt.y = 0; vInt = vInt.NormalizeTo(1000); this.destPosition += IntMath.Divide(vInt, (long)charInfo.iCollisionSize.x, 1000L); } this.destPosition.y = this.destPosition.y + this.hitHeight; } else if (this.MoveType == ActorMoveType.Directional) { VInt3 vInt2 = VInt3.one; if (this.skillContext == null) { return; } PoolObjHandle <ActorRoot> originator = this.skillContext.Originator; if (!originator) { return; } if (this.bBulletUseDir) { _action.refParams.GetRefParam("_BulletUseDir", ref vInt2); } else if (this.bUseIndicatorDir) { SkillUseContext refParamObject = _action.refParams.GetRefParamObject <SkillUseContext>("SkillContext"); VInt3 vInt3; if (refParamObject != null && refParamObject.CalcAttackerDir(out vInt3, originator)) { vInt2 = vInt3; } else { vInt2 = originator.get_handle().forward; } } else { vInt2 = originator.get_handle().forward; } vInt2 = vInt2.RotateY(this.offsetDir.y); if (this.bResetMoveDistance) { int num = 0; _action.refParams.GetRefParam("_BulletRealFlyingTime", ref num); int num2 = num * this.velocity / 1000; this.distance = ((num2 <= 0) ? this.distance : num2); } this.destPosition = this.moveActor.get_handle().location + vInt2.NormalizeTo(this.distance); this.destPosition.y = this.moveActor.get_handle().location.y; } else if (this.MoveType == ActorMoveType.Position) { if (this.bReachDestStop) { this.destPosition = this.targetPosition; } else { VInt3 vInt4 = this.targetPosition - this.moveActor.get_handle().location; vInt4.y = 0; vInt4 = vInt4.NormalizeTo(1000); this.destPosition = this.moveActor.get_handle().location + vInt4 * (this.length * this.velocity / 1000); VInt vInt5; if (PathfindingUtility.GetGroundY(this.destPosition, out vInt5)) { this.destPosition.y = vInt5.i; } } } if (this.bAdjustSpeed) { VInt3 vInt6 = this.destPosition - this.moveActor.get_handle().location; int num3 = this.length - 100; num3 = ((num3 > 0) ? num3 : this.length); this.velocity = (int)IntMath.Divide((long)vInt6.get_magnitude2D() * 1000L, (long)num3); } if (this.gravity < 0) { if (this.velocity == 0) { this.stopCondtion = true; return; } VInt3 vInt7 = this.destPosition - this.moveActor.get_handle().location; int num4; if (!this.shouldUseAcceleration) { num4 = (int)IntMath.Divide((long)vInt7.get_magnitude2D() * 1000L, (long)this.velocity); } else { long num5 = (long)this.velocity; long num6 = (long)this.acceleration; long num7 = (long)vInt7.get_magnitude2D(); long num8 = num5 * num5 + 2L * num6 * num7; num4 = (int)IntMath.Divide(((long)IntMath.Sqrt(num8) - num5) * 1000L, num6); this.lastVelocity = (this.lastLerpVelocity = this.velocity); } if (num4 == 0) { this.stopCondtion = true; return; } VInt vInt8; if (PathfindingUtility.GetGroundY(this.destPosition, out vInt8)) { this.gravityControler.InitMotionControler(num4, vInt8.i - this.moveActor.get_handle().location.y, this.gravity); } else { this.gravityControler.InitMotionControler(num4, 0, this.gravity); } } }
public void Enter(Action _action) { this.skillContext = _action.refParams.GetRefParamObject <SkillUseContext>("SkillContext"); this.lastTime = 0; this.lastVelocity = (this.lastLerpVelocity = this.velocity); this.stopCondtion = false; this.moveActor = _action.GetActorHandle(this.targetId); if (!this.moveActor) { return; } this.gravityControler = new AccelerateMotionControler(); this.xControler = new xAxisAccelerateMotionControler(); this.moveActor.handle.ObjLinker.AddCustomMoveLerp(new CustomMoveLerpFunc(this.ActionMoveLerp)); if (this.MoveType == ActorMoveType.Target) { if (this.bFindTargetByRotateBodyBullet) { _action.refParams.GetRefParam("FindEnemyActor", ref this.tarActor); } else { this.tarActor = _action.GetActorHandle(this.destId); } if (!this.tarActor) { return; } this.destPosition = this.tarActor.handle.location; CActorInfo charInfo = this.tarActor.handle.CharInfo; if (charInfo != null) { this.hitHeight = charInfo.iBulletHeight; VInt3 a = this.moveActor.handle.location - this.destPosition; a.y = 0; a = a.NormalizeTo(1000); this.destPosition += IntMath.Divide(a, (long)charInfo.iCollisionSize.x, 1000L); } this.destPosition.y = this.destPosition.y + this.hitHeight; } else if (this.MoveType == ActorMoveType.Directional) { VInt3 vInt = VInt3.one; if (this.skillContext == null) { return; } PoolObjHandle <ActorRoot> originator = this.skillContext.Originator; if (!originator) { return; } if (this.bBulletUseDir) { _action.refParams.GetRefParam("_BulletUseDir", ref vInt); } else if (this.bUseIndicatorDir) { SkillUseContext refParamObject = _action.refParams.GetRefParamObject <SkillUseContext>("SkillContext"); VInt3 vInt2; if (refParamObject != null && refParamObject.CalcAttackerDir(out vInt2, originator)) { vInt = vInt2; } else { vInt = originator.handle.forward; } } else { vInt = originator.handle.forward; } this.moveActor.handle.forward = vInt; this.moveActor.handle.rotation = Quaternion.LookRotation((Vector3)vInt); vInt = vInt.RotateY(this.offsetDir.y); if (this.bResetMoveDistance) { int num = 0; _action.refParams.GetRefParam("_BulletRealFlyingTime", ref num); int num2 = num * this.velocity / 1000; this.distance = ((num2 > 0) ? num2 : this.distance); } this.destPosition = this.moveActor.handle.location + vInt.NormalizeTo(this.distance); this.destPosition.y = this.moveActor.handle.location.y; } else if (this.MoveType == ActorMoveType.Position) { if (this.bReachDestStop) { this.destPosition = this.targetPosition; } else { VInt3 lhs = this.targetPosition - this.moveActor.handle.location; lhs.y = 0; lhs = lhs.NormalizeTo(1000); this.destPosition = this.moveActor.handle.location + lhs * (this.length * this.velocity / 1000); VInt vInt3; if (PathfindingUtility.GetGroundY(this.destPosition, out vInt3)) { this.destPosition.y = vInt3.i; } } } else if (this.MoveType == ActorMoveType.RotateBody) { this.originateActor = this.skillContext.Originator; if (!this.originateActor) { DebugHelper.Assert(false, "产生子弹的originateActor不能为空!!!"); return; } this.rotateBodyBulletCount = Mathf.Clamp(this.rotateBodyBulletCount, 1, 360); this.rotateBodyCurDirDegreeAngle = 360 / this.rotateBodyBulletCount * this.skillContext.BulletPos.x; VInt3 vInt4 = this.moveActor.handle.forward.RotateY(-this.rotateBodyCurDirDegreeAngle); this.moveActor.handle.forward = vInt4; this.moveActor.handle.rotation = Quaternion.LookRotation((Vector3)vInt4); } if (this.bAdjustSpeed) { VInt3 vInt5 = this.destPosition - this.moveActor.handle.location; int num3 = this.length - 100; num3 = ((num3 <= 0) ? this.length : num3); this.velocity = (int)IntMath.Divide((long)vInt5.magnitude2D * 1000L, (long)num3); } if (this.gravity < 0) { if (this.velocity == 0) { this.stopCondtion = true; return; } VInt3 vInt6 = this.destPosition - this.moveActor.handle.location; int num4; if (!this.shouldUseAcceleration) { num4 = (int)IntMath.Divide((long)vInt6.magnitude2D * 1000L, (long)this.velocity); } else { long num5 = (long)this.velocity; long num6 = (long)this.acceleration; long num7 = (long)vInt6.magnitude2D; long a2 = num5 * num5 + 2L * num6 * num7; num4 = (int)IntMath.Divide(((long)IntMath.Sqrt(a2) - num5) * 1000L, num6); this.lastVelocity = (this.lastLerpVelocity = this.velocity); } if (num4 == 0) { this.stopCondtion = true; return; } VInt vInt7; if (PathfindingUtility.GetGroundY(this.destPosition, out vInt7)) { this.gravityControler.InitMotionControler(num4, vInt7.i - this.moveActor.handle.location.y, this.gravity); } else { this.gravityControler.InitMotionControler(num4, 0, this.gravity); } } if (this.bMoveOnXAxis) { this.zDirection = this.destPosition - this.moveActor.handle.location; this.xDirection = VInt3.Cross(VInt3.up, this.zDirection); this.zCurPosition = this.moveActor.handle.location; if (this.bReachDestStop) { int[] array = new int[3]; VInt3[] array2 = new VInt3[] { default(VInt3), default(VInt3), this.destPosition - this.moveActor.handle.location }; array2[0] = array2[2]; array2[1] = array2[2]; array2[0].NormalizeTo(this.distanceZ0); array2[1].NormalizeTo(this.distanceZ1); for (int i = 0; i < array.Length; i++) { if (!this.shouldUseAcceleration) { array[i] = (int)IntMath.Divide((long)array2[i].magnitude2D * 1000L, (long)this.velocity); } else { long num8 = (long)this.velocity; long num9 = (long)this.acceleration; long num10 = (long)array2[i].magnitude2D; long a3 = num8 * num8 + 2L * num9 * num10; array[i] = (int)IntMath.Divide(((long)IntMath.Sqrt(a3) - num8) * 1000L, num9); } } if (array[2] > array[1] && array[1] > array[0] && array[0] > 0) { this.xControler.InitMotionControler(array[0], array[1], array[2], this.distanceZ0, this.distanceZ1, this.distanceX); int desPostion = this.xControler.getDesPostion(); this.xDestPosition = this.xDirection; this.xDestPosition.NormalizeTo(Math.Abs(desPostion)); if (desPostion < 0) { this.xDestPosition = -this.xDestPosition; } } else { this.bMoveOnXAxis = false; } } } }
public void Enter(AGE.Action _action) { this.skillContext = _action.refParams.GetRefParamObject <SkillUseContext>("SkillContext"); this.lastTime = 0; this.lastVelocity = this.lastLerpVelocity = this.velocity; this.stopCondtion = false; this.moveActor = _action.GetActorHandle(this.targetId); if (this.moveActor != 0) { this.gravityControler = new AccelerateMotionControler(); this.moveActor.handle.ObjLinker.AddCustomMoveLerp(new CustomMoveLerpFunc(this.ActionMoveLerp)); if (this.MoveType == ActorMoveType.Target) { this.tarActor = _action.GetActorHandle(this.destId); if (this.tarActor == 0) { return; } this.destPosition = this.tarActor.handle.location; CActorInfo charInfo = this.tarActor.handle.CharInfo; if (charInfo != null) { this.hitHeight = charInfo.iBulletHeight; VInt3 a = this.moveActor.handle.location - this.destPosition; a.y = 0; a = a.NormalizeTo(0x3e8); this.destPosition += IntMath.Divide(a, (long)charInfo.iCollisionSize.x, 0x3e8L); } this.destPosition.y += this.hitHeight; } else if (this.MoveType == ActorMoveType.Directional) { VInt3 one = VInt3.one; if (this.skillContext == null) { return; } PoolObjHandle <ActorRoot> originator = this.skillContext.Originator; if (originator == 0) { return; } one = originator.handle.forward.RotateY(this.offsetDir.y); this.destPosition = this.moveActor.handle.location + one.NormalizeTo(this.distance); this.destPosition.y = this.moveActor.handle.location.y; } else if (this.MoveType == ActorMoveType.Position) { this.destPosition = this.targetPosition; } if (this.bAdjustSpeed) { VInt3 num3 = this.destPosition - this.moveActor.handle.location; int num4 = this.length - 100; num4 = (num4 > 0) ? num4 : this.length; this.velocity = (int)IntMath.Divide((long)(num3.magnitude2D * 0x3e8L), (long)num4); } if (this.gravity < 0) { if (this.velocity == 0) { this.stopCondtion = true; } else { VInt3 num5 = this.destPosition - this.moveActor.handle.location; int num6 = 0; if (!this.shouldUseAcceleration) { num6 = (int)IntMath.Divide((long)(num5.magnitude2D * 0x3e8L), (long)this.velocity); } else { long velocity = this.velocity; long acceleration = this.acceleration; long num9 = num5.magnitude2D; long num10 = (velocity * velocity) + ((2L * acceleration) * num9); num6 = (int)IntMath.Divide((long)((IntMath.Sqrt(num10) - velocity) * 0x3e8L), acceleration); this.lastVelocity = this.lastLerpVelocity = this.velocity; } if (num6 == 0) { this.stopCondtion = true; } else { VInt num11; if (PathfindingUtility.GetGroundY(this.destPosition, out num11)) { this.gravityControler.InitMotionControler(num6, num11.i - this.moveActor.handle.location.y, this.gravity); } else { this.gravityControler.InitMotionControler(num6, 0, this.gravity); } } } } } }
public override void Enter(AGE.Action _action, Track _track) { this.done_ = false; this.lastTime_ = 0; base.Enter(_action, _track); this.actor_ = _action.GetActorHandle(this.actorId); if ((this.actor_ != 0) && ((this.teleport || (this.moveSpeed != 0)) || (this.acceleration != 0))) { this.srcPos = this.actor_.handle.location; if (this.bUseRecordPosition && (this.actor_.handle.SkillControl != null)) { this.destPos = this.actor_.handle.SkillControl.RecordPosition; this.dir = this.destPos - this.srcPos; VInt3 num8 = this.destPos - this.srcPos; int num2 = num8.magnitude2D; this.moveDistance += num2; } else if (this.moveType == ActorMoveType.Target) { int num3; PoolObjHandle <ActorRoot> actorHandle = _action.GetActorHandle(this.destId); if ((this.actor_ == 0) || (actorHandle == 0)) { this.actor_.Release(); return; } if (actorHandle.handle.ActorControl.GetNoAbilityFlag(ObjAbilityType.ObjAbility_MoveCity)) { num3 = 0; } else { this.dir = actorHandle.handle.location - this.srcPos; VInt3 num9 = actorHandle.handle.location - this.srcPos; num3 = num9.magnitude2D; } this.moveDistance += num3; } else if (this.moveType == ActorMoveType.Position) { this.dir = this.destPos - this.srcPos; VInt3 num10 = this.destPos - this.srcPos; int minMoveDistance = num10.magnitude2D; if (minMoveDistance < this.minMoveDistance) { minMoveDistance = this.minMoveDistance; } this.moveDistance += minMoveDistance; } else if (this.moveType == ActorMoveType.Directional) { this.dir = this.actor_.handle.forward; } this.dir.y = 0; this.actor_.handle.ActorControl.TerminateMove(); if (this.bRecordPosition && (this.actor_.handle.SkillControl != null)) { this.actor_.handle.SkillControl.RecordPosition = this.actor_.handle.location; } if (!this.actor_.handle.isMovable || (this.dir.sqrMagnitudeLong <= 1L)) { this.actor_.Release(); this.done_ = true; } else { VInt3 dir = this.dir; this.finalPos = this.srcPos + dir.NormalizeTo(this.moveDistance); if (!PathfindingUtility.IsValidTarget((ActorRoot)this.actor_, this.finalPos)) { this.IgnoreCollision = false; } if (!this.shouldUseAcceleration) { this.moveTick = (this.moveDistance * 0x3e8) / this.moveSpeed; } else { long moveDistance = this.moveDistance; long acceleration = this.acceleration; long moveSpeed = this.moveSpeed; this.moveTick = (int)IntMath.Divide((long)((IntMath.Sqrt((moveSpeed * moveSpeed) + ((2L * acceleration) * moveDistance)) - moveSpeed) * 0x3e8L), acceleration); this.lastMoveSpeed = this.moveSpeed; this.lastLerpMoveSpeed = this.moveSpeed; } this.actor_.handle.ActorControl.AddNoAbilityFlag(ObjAbilityType.ObjAbility_Move); this.actor_.handle.ObjLinker.AddCustomMoveLerp(new CustomMoveLerpFunc(this.ActionMoveLerp)); this.fromRot = this.actor_.handle.rotation; this.actor_.handle.MovementComponent.SetRotate(this.dir, true); if (this.rotationTime > 0) { this.toRot = Quaternion.LookRotation((Vector3)this.actor_.handle.forward); } else { this.actor_.handle.rotation = Quaternion.LookRotation((Vector3)this.actor_.handle.forward); } } } }
private static void MoveAlongEdge(TriangleMeshNode node, int edge, Int3 srcLoc, Int3 destLoc, out Int3 result, bool checkAnotherEdge = true) { Int3 vertex = node.GetVertex(edge); Int3 vertex2 = node.GetVertex((edge + 1) % 3); Int3 vInt = destLoc - srcLoc; vInt.y = 0; Int3 vInt2 = vertex2 - vertex; vInt2.y = 0; vInt2.NormalizeTo(1000); int num; num = vInt2.x * vInt.x + vInt2.z * vInt.z; bool flag; Int3 rhs = Polygon.IntersectionPoint(ref vertex, ref vertex2, ref srcLoc, ref destLoc, out flag); if (!flag) { if (!Polygon.IsColinear(vertex, vertex2, srcLoc) || !Polygon.IsColinear(vertex, vertex2, destLoc)) { result = srcLoc; return; } if (num >= 0) { int num2 = vInt2.x * (vertex2.x - vertex.x) + vInt2.z * (vertex2.z - vertex.z); int num3 = vInt2.x * (destLoc.x - vertex.x) + vInt2.z * (destLoc.z - vertex.z); rhs = ((num2 <= num3) ? vertex2 : destLoc); } else { int num4 = -vInt2.x * (vertex.x - vertex2.x) - vInt2.z * (vertex.z - vertex2.z); int num5 = -vInt2.x * (destLoc.x - vertex2.x) - vInt2.z * (destLoc.z - vertex2.z); rhs = ((Mathf.Abs(num4) <= Mathf.Abs(num5)) ? vertex : destLoc); } } int num6 = -IntMath.Sqrt(vertex.XZSqrMagnitude(rhs) * 1000000L); int num7 = IntMath.Sqrt(vertex2.XZSqrMagnitude(rhs) * 1000000L); if (num >= num6 && num <= num7) { result = IntMath.Divide(vInt2, (long)num, 1000000L) + rhs; if (!node.ContainsPoint(result)) { Vector3 vector = (Vector3)(vertex2 - vertex); vector.y = 0f; vector.Normalize(); Int3 lhs = vertex2 - vertex; lhs.y = 0; lhs *= 10000; long num8 = (long)lhs.magnitude; IntFactor vFactor = default(IntFactor); vFactor.numerator = (long)num; vFactor.denominator = num8 * 1000L; int num9; int num10; PathfindingUtility.getMinMax(out num9, out num10, (long)lhs.x, ref vFactor); int num11; int num12; PathfindingUtility.getMinMax(out num11, out num12, (long)lhs.z, ref vFactor); if (!PathfindingUtility.MakePointInTriangle(ref result, node, num9, num10, num11, num12, srcLoc) && !PathfindingUtility.MakePointInTriangle(ref result, node, num9 - 4, num10 + 4, num11 - 4, num12 + 4, srcLoc)) { result = srcLoc; } } if (PathfindingUtility.MoveAxisY) { PathfindingUtility.CalculateY(ref result, node); } } else { int rhs2; int edge2; Int3 vInt4; if (num < num6) { rhs2 = num - num6; edge2 = (edge + 2) % 3; vInt4 = vertex; } else { rhs2 = num - num7; edge2 = (edge + 1) % 3; vInt4 = vertex2; } Int3 vInt5 = vInt2 * rhs2 / 1000000f; int startEdge; TriangleMeshNode neighborByEdge = node.GetNeighborByEdge(edge2, out startEdge); if (neighborByEdge != null) { PathfindingUtility.checkedNodes.Add(node); PathfindingUtility.MoveFromNode(neighborByEdge, startEdge, vInt4, vInt5 + vInt4, out result); } else { if (checkAnotherEdge) { Int3 vertex3 = node.GetVertex((edge + 2) % 3); Int3 lhs2 = (vertex3 - vInt4).NormalizeTo(1000); if (Int3.Dot(lhs2, vInt5) > 0) { PathfindingUtility.checkedNodes.Add(node); PathfindingUtility.MoveAlongEdge(node, edge2, vInt4, vInt5 + vInt4, out result, false); return; } } result = vInt4; } } }
//GG //public void QueryRec(int i, Rect r) public void QueryRec(int i, VRect r) { // Determine the radius that we need to search to take all agents into account // Note: the second agentRadius usage should actually be the radius of the other agents, not this agent // but for performance reasons and for simplicity we assume that agents have approximately the same radius. // Thus an agent with a very small radius may in some cases detect an agent with a very large radius too late // however this effect should be minor. var radius = System.Math.Min(System.Math.Max((nodes[i].maxSpeed + speed) * timeHorizon, agentRadius) + agentRadius, maxRadius); if (nodes[i].child00 == i) { // Leaf node for (Agent a = nodes[i].linkedList; a != null; a = a.next) { //GG //float v = agent.InsertAgentNeighbour(a, radius * radius); long v = agent.InsertAgentNeighbour(a, (int)(radius * radius)); // Limit the search if the agent has hit the max number of nearby agents threshold if (v < maxRadius * maxRadius) { //GG //maxRadius = Mathf.Sqrt(v); maxRadius = IntMath.Sqrt(v); } } } else { // Not a leaf node //GG //Vector2 c = r.center; VInt2 c = r.center; if (p.x - radius < c.x) { if (p.y - radius < c.y) { //GG //QueryRec(nodes[i].child00, Rect.MinMaxRect(r.xMin, r.yMin, c.x, c.y)); QueryRec(nodes[i].child00, VRect.MinMaxRect(r.xMin, r.yMin, c.x, c.y)); radius = System.Math.Min(radius, maxRadius); } if (p.y + radius > c.y) { //GG //QueryRec(nodes[i].child01, Rect.MinMaxRect(r.xMin, c.y, c.x, r.yMax)); QueryRec(nodes[i].child01, VRect.MinMaxRect(r.xMin, c.y, c.x, r.yMax)); radius = System.Math.Min(radius, maxRadius); } } if (p.x + radius > c.x) { if (p.y - radius < c.y) { //GG //QueryRec(nodes[i].child10, Rect.MinMaxRect(c.x, r.yMin, r.xMax, c.y)); QueryRec(nodes[i].child10, VRect.MinMaxRect(c.x, r.yMin, r.xMax, c.y)); radius = System.Math.Min(radius, maxRadius); } if (p.y + radius > c.y) { //GG //QueryRec(nodes[i].child11, Rect.MinMaxRect(c.x, c.y, r.xMax, r.yMax)); QueryRec(nodes[i].child11, VRect.MinMaxRect(c.x, c.y, r.xMax, r.yMax)); } } } }