//Update and set all animation properties related to movement private void UpdateMovementAnimations(Vector3 moveDir) { //lerp movement floats so blend tree is smooth float currentFDirection = AnimatorRef.GetFloat("ForwardDirection"); float currentRDirection = AnimatorRef.GetFloat("RightDirection"); //forward direction if (MathFunc.AlmostEquals(currentFDirection, moveDir.z)) { currentFDirection = moveDir.z; } else if (moveDir.z < currentFDirection) { currentFDirection -= Time.deltaTime * 2.0f; } else if (moveDir.z > currentFDirection) { currentFDirection += Time.deltaTime * 2.0f; } //left/right direction if (MathFunc.AlmostEquals(currentRDirection, moveDir.x)) { currentRDirection = moveDir.x; } else if (moveDir.x < currentRDirection) { currentRDirection -= Time.deltaTime * 2.0f; } else if (moveDir.x > currentRDirection) { currentRDirection += Time.deltaTime * 2.0f; } if (m_IsSprinting) { AnimatorRef.SetFloat("ForwardDirection", currentFDirection); } else { AnimatorRef.SetFloat("ForwardDirection", Mathf.Clamp(currentFDirection, -1.0f, 0.5f)); } AnimatorRef.SetFloat("RightDirection", currentRDirection); AnimatorRef.SetBool("InAir", m_IsInAir); //if true, set animation for jumping off the ground AnimatorRef.SetBool("IsJumping", m_IsJumping); //if true, set animation for landing on the ground AnimatorRef.SetBool("IsLanding", m_IsLanding); }
public override void OnFirstTreeCall() { float randomXInRoom = Random.Range(0, m_RoomWidth); float randomZInRoom = Random.Range(0, m_RoomLength); Vector3 posInRoom = new Vector3(randomXInRoom, m_RoomHeight, randomZInRoom); posInRoom = m_AIReference.MyIslandRoom.transform.TransformPoint(posInRoom); Vector3 hitPoint = AIUtilits.CalcClosestPositionOnNavMeshBelowPos(posInRoom.x, posInRoom.z, posInRoom.y, m_AIReference.transform.position.y, 5.0f); if (!MathFunc.AlmostEquals(hitPoint, posInRoom)) { m_AIReference.Agent.SetDestination(hitPoint); } base.OnFirstTreeCall(); }
public override BehaviourState UpdateNodeBehaviour() { //if the agent isn't on the Nav mesh then it cannot possibly move on the nav mesh. Return failed. if (!m_AIReference.Agent.isOnNavMesh) { return(BehaviourState.Failed); } if (((m_AIReference.transform.position - m_AIReference.Target.transform.position).magnitude > MathFunc.LargeEpsilon) && !MathFunc.AlmostEquals(m_AIReference.Agent.destination, m_AIReference.Target.transform.position)) { m_AIReference.Agent.SetDestination(m_AIReference.Target.transform.position); } else { m_AIReference.Agent.ResetPath(); return(BehaviourState.Succeed); } return(BehaviourState.Running); }
private void MovePlayerToCenter() { foreach (Player player in m_PlayerList) { //get the line relative to the player Vector3 currentPlayerLine = LocalLineRenderer.GetPosition(player.PlayerNumber * 2 - 1); //get the direction to the player that the line tip needs to move to Vector3 directionToSpearTip = m_SpearHomePosition - currentPlayerLine; directionToSpearTip.Normalize(); //calculate the amount that the "chain" must move this frame towards the origin Vector3 amountToMove = (directionToSpearTip * ChainReturnSpeed * Time.deltaTime) + currentPlayerLine; //set the position in the local line renderer to represent the new location that the line renderer will be LocalLineRenderer.SetPosition(player.PlayerNumber * 2 - 1, amountToMove); //next if the player's photon view is the local one then we need to move the player if (player.photonView.isMine && m_PlayersBeingPulled[player.PlayerNumber - 1]) { //calcualte the direction that the player must travel in order to get back to the origin where the spear tip is located directionToSpearTip = m_SpearHomePosition - player.transform.position; directionToSpearTip.Normalize(); //calcualte the change in frames how much the player will travel player.transform.position += directionToSpearTip * Time.deltaTime * ChainReturnSpeed; //next we raycast to see if the player hit any thing right behind them when being pulled. This is done to see if the chain will break RaycastHit hit; if (Physics.Raycast(player.transform.position, directionToSpearTip, out hit, (player.transform.position - m_SpearHomePosition).magnitude)) { //check to see if the distance from the hit point to the player is almost nothing and if it is then break the chain if ((hit.point - player.transform.position).sqrMagnitude < (MathFunc.LargeEpsilon * MathFunc.LargeEpsilon)) { BreakChain(player); } } //finally we determine if the chain has returned and the local player's chain should be broken if (MathFunc.AlmostEquals(LocalLineRenderer.GetPosition(player.PlayerNumber * 2 - 1), LocalLineRenderer.GetPosition(0), 6.0f) || MathFunc.AlmostEquals(player.transform.position, m_SpearHomePosition, 5.0f)) { //if the positions pretty much overlap that means that it's time for the chain to break and the player to be released back into the wild BreakChain(player); } } bool attackFinished = false; //if there's more then 1 element in the players being pulled array then check if both values are true. If both values are true then //the chains no longer need to be pulled and the attack is over. else the attack is over if the only element in the array is true if (m_PlayersBeingPulled.Length > 1) { if (!m_PlayersBeingPulled[0] && !m_PlayersBeingPulled[1]) { attackFinished = true; } } else if (!m_PlayersBeingPulled[0]) { attackFinished = true; } //if the attack is done then set sendingchains to false and turn the local linerenderer off if (attackFinished) { m_SendingChains = false; LocalLineRenderer.enabled = false; } } }