// OVERRIDE METHODS: ---------------------------------------------------------------------- public override CharacterLocomotion.LOCOMOTION_SYSTEM Update() { base.Update(); if (this.characterLocomotion.navmeshAgent != null) { this.characterLocomotion.navmeshAgent.updatePosition = false; this.characterLocomotion.navmeshAgent.updateUpAxis = false; } Vector3 targetDirection = this.desiredDirection; ILocomotionDriver locomotionDriver = this.characterLocomotion.locomotionDriver; Vector3 characterForward = locomotionDriver.transform.TransformDirection(Vector3.forward); float targetSpeed = this.CalculateSpeed(targetDirection, locomotionDriver.IsGrounded()); if (targetDirection == Vector3.zero) { targetDirection = this.movementDirection; targetSpeed = 0f; } float speed = this.CalculateAccelerationFromSpeed(targetSpeed); Quaternion targetRotation = this.UpdateRotation(targetDirection); this.UpdateAnimationConstraints(ref targetDirection, ref targetRotation); targetDirection *= speed; this.UpdateSliding(); if (this.isSliding) { targetDirection = this.slideDirection; } targetDirection += this.characterLocomotion.GetMomentum(); if (this.isDashing) { targetDirection = this.dashVelocity; targetRotation = locomotionDriver.transform.rotation; } locomotionDriver.SetVelocity(targetDirection); locomotionDriver.transform.rotation = targetRotation; if (this.characterLocomotion.navmeshAgent != null && this.characterLocomotion.navmeshAgent.isActiveAndEnabled) { this.characterLocomotion.navmeshAgent.enabled = false; } return(CharacterLocomotion.LOCOMOTION_SYSTEM.LocomotionDriver); }
// INITIALIZERS: -------------------------------------------------------------------------- public void Setup(Character character) { this.lastGroundTime = Time.fixedTime; this.character = character; this.locomotionDriver = this.character.GetComponent <ILocomotionDriver>(); this.currentLocomotionType = LOCOMOTION_SYSTEM.LocomotionDriver; this.locomotionDriver.Setup(this.character); this.GenerateNavmeshAgent(); this.SetDirectionalDirection(Vector3.zero); }
public override bool InstantExecute(GameObject target, IAction[] actions, int index) { Character _character = this.character.GetCharacter(target); if (_character == null) { return(true); } ILocomotionDriver locomotionDriver = _character.characterLocomotion.locomotionDriver; _character.enabled = !this.mounted; locomotionDriver.SetCollisionDetection(!this.mounted); return(true); }
// INITIALIZERS: -------------------------------------------------------------------------- public void Setup(Character character) { this.character = character; this.characterAnimator = this.character.GetCharacterAnimator(); this.animator = this.characterAnimator.animator; this.locomotionDriver = gameObject.GetComponentInParent <ILocomotionDriver>(); if (this.animator == null || !this.animator.isHuman || this.locomotionDriver == null) { return; } Transform lFoot = this.animator.GetBoneTransform(HumanBodyBones.LeftFoot); Transform rFoot = this.animator.GetBoneTransform(HumanBodyBones.RightFoot); this.leftFoot = new Foot(lFoot, AvatarIKGoal.LeftFoot, IK_L_FOOT); this.rightFoot = new Foot(rFoot, AvatarIKGoal.RightFoot, IK_R_FOOT); this.defaultOffset = transform.localPosition.y; }
// OVERRIDE METHODS: ---------------------------------------------------------------------- public override CharacterLocomotion.LOCOMOTION_SYSTEM Update() { base.Update(); if (!this.move) { if (!this.usingNavmesh) { Vector3 defaultDirection = Vector3.up * this.characterLocomotion.verticalSpeed; this.characterLocomotion.locomotionDriver.SetVelocity(defaultDirection); return(CharacterLocomotion.LOCOMOTION_SYSTEM.LocomotionDriver); } this.characterLocomotion.navmeshAgent.enabled = true; return(CharacterLocomotion.LOCOMOTION_SYSTEM.NavigationMeshAgent); } if (this.usingNavmesh) { NavMeshAgent agent = this.characterLocomotion.navmeshAgent; agent.enabled = true; ILocomotionDriver locomotionDriver = this.characterLocomotion.locomotionDriver; if (agent.pathPending) { return(CharacterLocomotion.LOCOMOTION_SYSTEM.NavigationMeshAgent); } if (!agent.hasPath || agent.pathStatus != NavMeshPathStatus.PathComplete) { float distance = Mathf.Min( Vector3.Distance(agent.pathEndPosition, agent.transform.position), agent.remainingDistance ); if (!agent.hasPath && distance < STOP_THRESHOLD) { this.Stopping(); } return(CharacterLocomotion.LOCOMOTION_SYSTEM.NavigationMeshAgent); } float remainingDistance = agent.remainingDistance; bool isGrounded = agent.isOnOffMeshLink; agent.speed = this.CalculateSpeed(locomotionDriver.transform.forward, isGrounded); agent.angularSpeed = this.characterLocomotion.angularSpeed; agent.isStopped = false; agent.updateRotation = true; if (remainingDistance <= this.stopThreshold) { agent.updateRotation = true; this.Stopping(); } else if (remainingDistance <= this.stopThreshold + SLOW_THRESHOLD) { this.Slowing(remainingDistance); } else { this.Moving(); } this.UpdateNavmeshAnimationConstraints(); return(CharacterLocomotion.LOCOMOTION_SYSTEM.NavigationMeshAgent); } else { if (this.characterLocomotion.navmeshAgent != null && this.characterLocomotion.navmeshAgent.enabled) { this.characterLocomotion.navmeshAgent.enabled = false; } ILocomotionDriver locomotionDriver = this.characterLocomotion.locomotionDriver; Vector3 targetPos = Vector3.Scale(this.targetPosition, HORIZONTAL_PLANE); targetPos += Vector3.up * locomotionDriver.transform.position.y; Vector3 targetDirection = (targetPos - locomotionDriver.transform.position).normalized; float speed = this.CalculateSpeed(targetDirection, locomotionDriver.IsGrounded()); speed = this.CalculateAccelerationFromSpeed(speed); Quaternion targetRot = this.UpdateRotation(targetDirection); this.UpdateAnimationConstraints(ref targetDirection, ref targetRot); targetDirection = Vector3.Scale(targetDirection, HORIZONTAL_PLANE) * speed; targetDirection += Vector3.up * this.characterLocomotion.verticalSpeed; locomotionDriver.SetVelocity(targetDirection); locomotionDriver.transform.rotation = targetRot; float remainingDistance = (Vector3.Distance( Vector3.Scale(locomotionDriver.transform.position, HORIZONTAL_PLANE), Vector3.Scale(this.targetPosition, HORIZONTAL_PLANE) )); if (remainingDistance <= this.stopThreshold) { this.Stopping(); } else if (remainingDistance <= this.stopThreshold + SLOW_THRESHOLD) { this.Slowing(remainingDistance); } return(CharacterLocomotion.LOCOMOTION_SYSTEM.LocomotionDriver); } }
// OVERRIDE METHODS: ---------------------------------------------------------------------- public override CharacterLocomotion.LOCOMOTION_SYSTEM Update() { base.Update(); Vector3 currPosition = this.characterLocomotion.character.transform.position; float distance = (this.targetTransform != null ? Vector3.Distance(currPosition, this.targetTransform.position) : -1.0f ); bool stopConditions = this.targetTransform == null; stopConditions |= (this.isFollowing && distance <= this.minRadius); stopConditions |= (!this.isFollowing && distance <= this.maxRadius); if (stopConditions) { this.isFollowing = false; if (this.usingNavmesh) { this.characterLocomotion.navmeshAgent.enabled = true; this.characterLocomotion.navmeshAgent.isStopped = true; } else { Vector3 defaultDirection = Vector3.up * this.characterLocomotion.verticalSpeed; float speed = this.CalculateAccelerationFromSpeed(0f); defaultDirection += this.aimDirection * speed; this.characterLocomotion.locomotionDriver.SetVelocity(defaultDirection); } return(this.usingNavmesh ? CharacterLocomotion.LOCOMOTION_SYSTEM.NavigationMeshAgent : CharacterLocomotion.LOCOMOTION_SYSTEM.LocomotionDriver ); } this.isFollowing = true; if (this.usingNavmesh) { NavMeshAgent agent = this.characterLocomotion.navmeshAgent; agent.enabled = true; agent.updatePosition = true; agent.updateUpAxis = true; ILocomotionDriver locomotionDriver = this.characterLocomotion.locomotionDriver; NavMeshHit hit = new NavMeshHit(); NavMesh.SamplePosition(this.targetTransform.position, out hit, 1.0f, NavMesh.AllAreas); if (hit.hit) { agent.SetDestination(hit.position); } float remainingDistance = agent.remainingDistance; bool isGrounded = agent.isOnOffMeshLink; agent.speed = this.CalculateSpeed(locomotionDriver.transform.forward, isGrounded); agent.angularSpeed = this.characterLocomotion.angularSpeed; agent.isStopped = false; agent.updateRotation = true; this.UpdateNavmeshAnimationConstraints(); return(CharacterLocomotion.LOCOMOTION_SYSTEM.NavigationMeshAgent); } else { if (this.characterLocomotion.navmeshAgent != null) { this.characterLocomotion.navmeshAgent.enabled = false; } ILocomotionDriver locomotionDriver = this.characterLocomotion.locomotionDriver; Vector3 targetPosition = Vector3.Scale(this.targetTransform.position, HORIZONTAL_PLANE); targetPosition += Vector3.up * currPosition.y; Vector3 targetDirection = (targetPosition - currPosition).normalized; float speed = this.CalculateSpeed(targetDirection, locomotionDriver.IsGrounded()); speed = this.CalculateAccelerationFromSpeed(speed); Quaternion targetRotation = this.UpdateRotation(targetDirection); this.UpdateAnimationConstraints(ref targetDirection, ref targetRotation); targetDirection = Vector3.Scale(targetDirection, HORIZONTAL_PLANE) * speed; targetDirection += this.characterLocomotion.GetMomentum(); locomotionDriver.SetVelocity(targetDirection); locomotionDriver.transform.rotation = targetRotation; if (this.characterLocomotion.navmeshAgent != null && this.characterLocomotion.navmeshAgent.isOnNavMesh) { Vector3 position = this.characterLocomotion.locomotionDriver.transform.position; this.characterLocomotion.navmeshAgent.Warp(position); } return(CharacterLocomotion.LOCOMOTION_SYSTEM.LocomotionDriver); } }