protected virtual IEnumerator TraverseOffMeshLink(RichSpecial rs) { var link = rs.nodeLink as AnimationLink; if (link == null) { Debug.LogError("Unhandled RichSpecial"); yield break; } // Rotate character to face the correct direction while (true) { var origRotation = ai.rotation; var finalRotation = ai.SimulateRotationTowards(rs.first.forward, ai.rotationSpeed * Time.deltaTime); // Rotate until the rotation does not change anymore if (origRotation == finalRotation) { break; } ai.FinalizeMovement(ai.position, finalRotation); yield return(null); } // Reposition transform.parent.position = transform.position; transform.parent.rotation = transform.rotation; transform.localPosition = Vector3.zero; transform.localRotation = Quaternion.identity; // Set up animation speeds if (rs.reverse && link.reverseAnim) { anim[link.clip].speed = -link.animSpeed; anim[link.clip].normalizedTime = 1; anim.Play(link.clip); anim.Sample(); } else { anim[link.clip].speed = link.animSpeed; anim.Rewind(link.clip); anim.Play(link.clip); } // Fix required for animations in reverse direction transform.parent.position -= transform.position - transform.parent.position; // Wait for the animation to finish yield return(new WaitForSeconds(Mathf.Abs(anim[link.clip].length / link.animSpeed))); }
void AgentMove() { //if (seeker.destination == m_destination) // return; if (!m_walking) { return; } agent.destination = m_destination; Vector3 nextPosition; Quaternion nextRotation; agent.MovementUpdate(Time.deltaTime, out nextPosition, out nextRotation); if (!controller) { deltaPosition = new Vector3(animator.rootPosition.x, nextPosition.y, animator.rootPosition.z); } //deltaPosition = nextPosition; else { deltaPosition = new Vector3(animator.rootPosition.x, nextPosition.y, animator.rootPosition.z); //deltaPosition = nextPosition; Vector3 delta = controller.CalculateMovementDelta(animatedObject.transform.position, Time.deltaTime); deltaPosition = new Vector3(deltaPosition.x + delta.x, deltaPosition.y, deltaPosition.z + delta.z); } agent.FinalizeMovement(deltaPosition, nextRotation); transform.rotation = nextRotation; //if (agent.destination == m_destination) // return; //agent.destination = m_destination; //if (agent.pathStatus == NavMeshPathStatus.PathInvalid || agent.pathStatus == NavMeshPathStatus.PathPartial) //{ // m_walking = false; // agent.isStopped = true; // return; //} //if (agent.isStopped) // agent.isStopped = false; //m_walking = true; //agent.nextPosition = animatedObject.transform.position; //transform.rotation = agent.transform.rotation; }
public virtual bool MoveToPosition() { // Calculate how the AI wants to move ai.MovementUpdate(Time.deltaTime, out nextPosition, out nextRotation); localDesiredVelocity = transform.InverseTransformDirection(ai.desiredVelocity); localDesiredVelocity.y = 0; // we don't want our player floating so ignore y axis if (!useRootPosition) { ai.FinalizeMovement(transform.position, nextRotation); } else { transform.position = anim.rootPosition; } if (!useRootRotation) { transform.rotation = nextRotation; } else { transform.rotation = anim.rootRotation; } angle = Player.Utility.FindSignedAngle(transform.forward, (ai.steeringTarget - transform.position)); EnableMovement(); // Update animation parameters UpdateMoveAnimations(localDesiredVelocity, angle, shouldMove); if (Vector3.Distance(ai.destination, transform.position) <= ai.endReachedDistance) { DisableMovement(); Debug.Log("Reached Objective"); return(true); } return(false); }
public virtual bool MoveToPosition() { _blackboard.targetReachedStatus = false; // Calculate how the _ai wants to move _ai.MovementUpdate(Time.deltaTime, out _nextPosition, out _nextRotation); _localDesiredVelocity = transform.InverseTransformDirection(_ai.desiredVelocity); _localDesiredVelocity.y = 0; // we don't want our player floating so ignore y axis if (!useRootPosition) { _ai.FinalizeMovement(transform.position, _nextRotation); } else { transform.position = _anim.rootPosition; } if (!useRootRotation) { transform.rotation = _nextRotation; } else { transform.rotation = _anim.rootRotation; } _angle = Player.Utility.FindSignedAngle(transform.forward, (_ai.steeringTarget - transform.position)); EnableMovement(); if (Vector3.Distance(_ai.destination, transform.position) <= _ai.endReachedDistance) { _blackboard.targetReachedStatus = true; DisableMovement(); return(true); } return(false); }