public override void GetDesiredSteering(SteeringResult rst) { if (Finish) { return; } if (Vector3d.SqrDistance(Target, Self.Position) < FixedMath.One / 100) { Finish = true; GridService.Clear(Target, Self as SceneObject); GridService.TagAs(Self.Position, Self as SceneObject, GridService.NodeType.BeTaken); return; } if (GridService.IsNotEmptyBy(Target) != Self) { GridService.SearchNearEmptyPoint(Target, out Target); GridService.TagAs(Target, Self as SceneObject, GridService.NodeType.FlagAsTarget); } Vector3d dir = Target - Self.Position; Vector3d desiredVelocity = dir.Normalize() * Self.Speed; var acc = (desiredVelocity - Self.Velocity) / (LockFrameMgr.FixedFrameTime); rst.DesiredSteering = acc; }
protected override void OnExit() { base.OnExit(); GridService.Clear(Target, Self as SceneObject); }
public override void GetDesiredSteering(SteeringResult rst) { if (Finish) { return; } if (_firstStart) { _index = 0; if (Path != null && Path.Count > 0) { Target = Path[_index]; _finalTarget = Path[Path.Count - 1]; } else { Finish = true; return; } _firstStart = false; } if (Arrive()) { Self.Position = Target; GridService.Clear(Target, Self as SceneObject); _index++; if (_index == Path.Count) { GridService.TagAs(Target, Self as SceneObject, GridService.NodeType.BeTaken); Finish = true; return; } Target = Path[_index]; } if (Vector3d.SqrDistance(Self.Position, _finalTarget) <= FixedMath.Create(Radius)) { _index = Path.Count - 1; } if (_index == Path.Count - 1) { if (GridService.IsNotEmptyBy(Target) != Self) //|| (_caculatedIndex&(_index+1)) == 0) { // _caculatedIndex += _index + 1; Vector3d t; if (Formation == Formation.Quad) { GridService.SearchNearEmptyPoint(Path[_index], out t); } else { GridService.SearchNearCircleEmptyPoint(Self.Position, Path[_index], Radius, out t); } Target = t; GridService.TagAs(Target, Self as SceneObject, GridService.NodeType.FlagAsTarget); } } Vector3d desiredVelocity = _so.Forward * Self.Speed; var nextPosi = Self.Position + desiredVelocity * LockFrameMgr.FixedFrameTime; if (!JPSAStar.active.IsWalkable(nextPosi)) { List <PathFinderNode> list = new List <PathFinderNode>(); JPSAStar.active.AStarFindPath(Self.Position, Target, list); for (int i = 0; i < list.Count - 1; i++) { Path.Insert(0, JPSAStar.active.P2V(list[i])); } Target = Path[0]; } Self.Position += desiredVelocity * LockFrameMgr.FixedFrameTime; UnityEngine.Debug.DrawLine(Self.Position.ToVector3(), Target.ToVector3(), Color.red, 0.1f); }