public override void Update() { Vector3 position = Vector3.zero; float targetXZDistanceSq = 0f; // No entity, so no need to do anything. if (this.entityTarget == null) { return; } // Let the entity keep looking at you, otherwise it may just sping around. this.theEntity.SetLookPosition(this.entityTarget.getHeadPosition()); this.theEntity.RotateTo(this.entityTarget.position.x, this.entityTarget.position.y + 2, this.entityTarget.position.z, 30f, 30f); // Find the location of the entity, and figure out where it's at. position = this.entityTarget.position; targetXZDistanceSq = base.GetTargetXZDistanceSq(6); if (entityAliveSDX) { if (entityAliveSDX.CanExecuteTask(EntityAliveSDX.Orders.SetPatrolPoint)) { // Make them a lot closer to you when they are following you. this.distanceToEntity = 1f; entityAliveSDX.UpdatePatrolPoints(this.theEntity.world.FindSupportingBlockPos(this.entityTarget.position)); } } Vector3 a = position - this.entityTargetPos; if (a.sqrMagnitude < 1f) { this.entityTargetVel = this.entityTargetVel * 0.7f + a * 0.3f; } this.entityTargetPos = position; this.theEntity.moveHelper.CalcIfUnreachablePos(position); // num is used to determine how close and comfortable the entity approaches you, so let's make sure they respect some personal space if (distanceToEntity < 1) { distanceToEntity = 3; } // if the entity is not calculating a path, check how many nodes are left, and reset the path counter if its too low. if (!PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId)) { PathEntity path = this.theEntity.navigator.getPath(); if (path != null && path.NodeCountRemaining() <= 2) { this.pathCounter = 0; } } if (--this.pathCounter <= 0 && !PathFinderThread.Instance.IsCalculatingPath(this.theEntity.entityId)) { // If its still not calculating a path, find a new path to the leader this.pathCounter = 6 + this.theEntity.GetRandom().Next(10); PathFinderThread.Instance.FindPath(this.theEntity, this.entityTarget.position, this.theEntity.GetMoveSpeedAggro(), true, this); } if (this.theEntity.Climbing) { return; } // If there's no path, calculate one. if (this.theEntity.navigator.noPathAndNotPlanningOne()) { PathFinderThread.Instance.FindPath(this.theEntity, this.entityTarget.position, this.theEntity.GetMoveSpeedAggro(), true, this); } }