// Update is called once per frame void Update() { if (playerPos != player.transform.position && (transform.position - player.transform.position).magnitude < followDistance) { playerPos = player.transform.position; appearancreController.SetNewGoal(playerPos + Vector3.up * height); } else { appearancreController.SetNewGoal(transform.forward + transform.position); } appearancreController.UpdateAppearance(); if (myQuest != null) { if (myQuest.HasStarted()) { myQuest.QuestUpdate(); } } }
// Update is called once per frame public bool UpdateMovement() { bool changed = false; if (!pause) { //gravity if (Map.Instance.IsPositionOpen(GetExpectedGroundPosition())) { transform.position -= Vector3.up * Time.deltaTime * gravitySpeed; changed = true; } //pathing handling if (currState == PATHING) { //If no path, find one if (path == null || path.Length == 0) { if (transform.position != _currGoal) { path = AStar(transform.position, _currGoal); pathIndex = 0; if (path != null) { appearanceHandler.SetNewGoal(GetNPCEyePositionFromPathPoint(path[pathIndex])); } } } //If path, then move between points else { //Distance to the next node Vector3 distToNext = GetNPCPositionFromPathPoint(path[pathIndex]) - transform.position; //Are we done at this point if (distToNext.magnitude < _minDist) { transform.position = GetNPCPositionFromPathPoint(path[pathIndex]); pathIndex++; changed = true; //Altered the path index if (pathIndex >= path.Length) { path = null; //Did we reach the end of the path } else { //Ensure that the next position is still available if (IsViablePosition(new Vector3i(path[pathIndex]))) { appearanceHandler.SetNewGoal(GetNPCEyePositionFromPathPoint(path[pathIndex])); //On to the next point in the path _currGoal = path[pathIndex]; } else { //REPLAN path = null; } } } else { //Moving towards the next one float speedToUse = speed; //Make sure the npc can escape gravity if (changed) { speedToUse = gravitySpeed + speed; } transform.position += distToNext.normalized * Time.deltaTime * speedToUse; changed = true; } } } } moving = changed; return(changed); }