public void DoFollow() { Coordinate sourceCoord = this.Character.Coordinates(); Vector3 targetPosition = this.followCoordinates; if (!this.followIdentity.Equals(Identity.None)) { ICharacter targetChar = Pool.Instance.GetObject <ICharacter>( this.Character.Playfield.Identity, this.followIdentity); if (targetChar == null) { // If target does not longer exist (death or zone or logoff) then stop following this.followIdentity = Identity.None; this.followCoordinates = new Vector3(); return; } targetPosition = targetChar.Coordinates().coordinate; } // Do we have coordinates to follow? if (targetPosition.Distance2D(new Vector3()) < 0.01f) { return; } // /!\ If target flies away, there has to be some kind of adjustment Vector3 start = sourceCoord.coordinate; Vector3 dest = targetPosition; // Check if we have arrived if (start.Distance2D(dest) < 0.3f) { this.StopMovement(); this.Character.RawCoordinates = dest; FollowTargetMessageHandler.Default.Send(this.Character, dest); this.followCoordinates = new Vector3(); return; } LogUtil.Debug(DebugInfoDetail.Movement, "Distance to target: " + start.Distance2D(dest).ToString()); // If target moved or first call, then issue a new follow if (targetPosition.Distance2D(this.followCoordinates) > 2.0f) { this.StopMovement(); this.Character.Coordinates(start); FollowTargetMessageHandler.Default.Send(this.Character, start); Vector3 temp = start - dest; temp.y = 0; this.Character.Heading = (Quaternion)Quaternion.GenerateRotationFromDirectionVector(temp); this.followCoordinates = dest; FollowTargetMessageHandler.Default.Send(this.Character, start, dest); this.StartMovement(); } }