// Update is called once per frame void Update() { AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(0); combatController.checkForMoveCombination(stateInfo); #region dynamic-collision-debug // var sphereRadius = sphere.GetComponent<SphereCollider>().radius; // var edgeOfSphere = new Vector3((sphere.transform.position.x) + (sphere.GetComponent<SphereCollider>().radius * sphere.transform.localScale.x), //(sphere.transform.position.y) + (sphere.GetComponent<SphereCollider>().radius * sphere.transform.localScale.y), //(sphere.transform.position.z) + (sphere.GetComponent<SphereCollider>().radius * sphere.transform.localScale.z)); // print(edgeOfSphere); // var edgeX = new Vector3(edgeOfSphere.x, sphere.transform.position.y, sphere.transform.position.z); // var edgeY = new Vector3(sphere.transform.position.x, edgeOfSphere.y, sphere.transform.position.z); // var edgeZ = new Vector3(sphere.transform.position.x, sphere.transform.position.y, edgeOfSphere.z); // Debug.DrawLine(sphere.transform.position, edgeX); // Debug.DrawLine(sphere.transform.position, edgeY); // Debug.DrawLine(sphere.transform.position, edgeZ); // Debug.DrawLine(sphere.transform.position, GunbaiCollision.collider.transform.position); // print("distance between sphereX and gunabi: " + Vector3.Distance(edgeX, GunbaiCollision.collider.transform.position)); // print("distance between sphereY and gunabi: " + Vector3.Distance(edgeY, GunbaiCollision.collider.transform.position)); // print("distance between sphereZ and gunabi: " + Vector3.Distance(edgeZ, GunbaiCollision.collider.transform.position)); // var dir = (GunbaiCollision.collider.transform.position - sphere.transform.position).normalized; // var distanceToMultiply = (edgeZ - sphere.transform.position).magnitude; // var edgeOfSphereWithGunabiDirection = sphere.transform.position + dir * distanceToMultiply; // Debug.DrawLine(sphere.transform.position, edgeOfSphereWithGunabiDirection, Color.red); // var edgeOfSphereToGunbaiCollider = Vector3.Distance(edgeOfSphereWithGunabiDirection, GunbaiCollision.collider.transform.position); // print("dist: " + edgeOfSphereToGunbaiCollider); // Debug.DrawLine(edgeOfSphereWithGunabiDirection, GunbaiCollision.collider.transform.position, Color.green); #endregion int pathStatus = PlayerMovement.Move(); if (pathStatus == 0) { //print("The agent can reach the destionation"); } else if (pathStatus == 1) { //print("The agent can only get close to the destination"); } else if (pathStatus == 2) { //print("The agent cannot reach the destination"); //print("hasFoundPath will be false"); } else { //no movement occured } //rotations and animations if (PlayerMovement.inControl(false)) { if (PlayerMovement.agent.hasPath) { if (stateInfo.IsName("IdleReady")) { anim.SetBool(isRunning, true); anim.SetBool(isIdleReady, false); } anim.SetFloat(speed, Mathf.Abs(PlayerMovement.agent.velocity.magnitude)); //check if difference between destination and current position is above a certain threshold to apply rotation if (Mathf.Abs((PlayerMovement.agent.steeringTarget - transform.position).x) > 1.0) { //create a new rotation from our transform, to the difference of position of the destination and ourselves with standard time var new_rot = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(PlayerMovement.agent.steeringTarget - transform.position), Time.deltaTime); //no x or z rotation to stop tilts new_rot = new Quaternion(0, new_rot.y, 0, new_rot.w); transform.rotation = new_rot; } } if (PlayerMovement.agent.remainingDistance <= PlayerMovement.agent.stoppingDistance) { if (PlayerMovement.agent.velocity.sqrMagnitude == 0f) { PlayerMovement.agent.ResetPath(); anim.SetBool(isRunning, false); anim.SetBool(isIdleReady, true); } } } if (Input.GetKeyDown(KeyCode.L)) { PlayerMovement.agent.ResetPath(); anim.SetBool(isCombat, true); anim.SetTrigger(isCounterState); } if (Input.GetKeyDown(KeyCode.V)) { PlayerMovement.agent.ResetPath(); anim.SetBool(isCombat, true); anim.SetTrigger(isCounterStateSuccess); } if (Input.GetKeyDown(KeyCode.B)) { PlayerMovement.agent.ResetPath(); anim.SetBool(isCombat, true); anim.SetTrigger(isCounterStateSuccess); anim.SetBool(isDead, true); } if (stateInfo.IsName("Counter")) { ResetAllCombatTriggers(); } if (stateInfo.IsName("Dazed")) { ResetAllCombatTriggers(); } //if (stateInfo.IsName("IdleReady") && !idleStateHasChanged) //{ // //only set time once then compare with current running time to get len // if (!timerStart) // { // anim.SetFloat(idleReadyDuration, Time.time); // timerStart = true; // anim.SetBool(isIdleReady, true); // } // //check if speed is fast enough to count as a run // //if (Mathf.Abs(movement.agent.velocity.magnitude) > 0.1) // //{ // // idleStateHasChanged = true; // // timerStart = false; // // anim.SetBool(isIdleReady, false); // // anim.SetBool(isRunning, true); // //} // //******** BROKEN ********** // //check if 5 seconds have elapsed since being in ready // //else if (Time.time - anim.GetFloat(idleReadyDuration) > 5f) // //{ // // idleStateHasChanged = true; // // timerStart = false; // // anim.SetBool(isIdleReady, false); // // anim.SetBool(isIdleReadyToIdleCalm, true); // //} //} ////if (stateInfo.IsName("Run")) ////{ //// idleStateHasChanged = false; //// if (Mathf.Abs(movement.agent.velocity.magnitude) < 0.1) //// { //// anim.SetBool(isRunning, false); //// anim.SetBool(isIdleReady, true); //// } ////} //if (stateInfo.IsName("IdleCalm")) //{ // idleStateHasChanged = false; // if (Mathf.Abs(movement.agent.velocity.magnitude) > 0.1) // { // anim.SetBool(isIdleReadyToIdleCalm, false); // anim.SetBool(isRunning, true); // } //} //iterates through all of the moves if there is no combat animation playing } //Update func
// Update is called once per frame void Update() { AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(0); combatController.checkForMoveCombination(stateInfo); int pathStatus = PlayerMovement.Move(); if (pathStatus == 0) { //print("The agent can reach the destionation"); } else if (pathStatus == 1) { //print("The agent can only get close to the destination"); } else if (pathStatus == 2) { //print("The agent cannot reach the destination"); //print("hasFoundPath will be false"); } else { //no movement occured } if (PlayerMovement.inControl(true)) { if (PlayerMovement.agent.hasPath) { if (anim.GetBool("isRunning") == false) { anim.SetBool(isRunning, true); anim.SetBool(isIdleReady, false); } anim.SetFloat(speed, Mathf.Abs(PlayerMovement.agent.speed)); //check if difference between destination and current position is above a certain threshold to apply rotation if (Mathf.Abs((PlayerMovement.agent.steeringTarget - transform.position).x) > 0.5) { //create a new rotation from our transform, to the difference of position of the destination and ourselves with standard time var new_rot = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(PlayerMovement.agent.steeringTarget - transform.position), Time.deltaTime); //no x or z rotation to stop tilts new_rot = new Quaternion(0, new_rot.y, 0, new_rot.w); transform.rotation = new_rot; } } if (PlayerMovement.agent.remainingDistance <= PlayerMovement.agent.stoppingDistance) { if (PlayerMovement.agent.velocity.sqrMagnitude == 0f) { PlayerMovement.agent.ResetPath(); anim.SetBool(isRunning, false); anim.SetBool(isIdleReady, true); } } } if (Input.GetKeyDown(KeyCode.Q)) { anim.SetTrigger(isDashing); } if (Input.GetKeyDown(KeyCode.E)) { PlayerMovement.agent.ResetPath(); anim.SetBool(isExhausted, true); } if (Input.GetKeyDown(KeyCode.R)) { anim.SetBool(isExhausted, false); } if (Input.GetKeyDown(KeyCode.L)) { setTriggerAndCancelMovement(isCounter); } if (Input.GetKeyDown(KeyCode.V)) { setTriggerAndCancelMovement(isCounterState); } if (Input.GetKeyDown(KeyCode.I)) { setTriggerAndCancelMovement(isInteraction); } if (Input.GetKeyDown(KeyCode.P)) { setTriggerAndCancelMovement(isExploit); } if (Input.GetKeyDown(KeyCode.L)) { setTriggerAndCancelMovement(isDefeated); } }
public void checkForMoveCombination(AnimatorStateInfo stateInfo) { //if there's an animation playing, no need to check for anything if (combatAnimationInitiated) { skipMoveCombinationCheck = true; } foreach (var move in tierList) { if (skipMoveCombinationCheck) { break; } if (Input.GetKeyDown(move.Combo[0].ToString()) && move.ComboPressed.Count == 0) { move.ComboPressed.Add(move.Combo[0].ToString()); } if (move.ComboPressed.Count == 1) { if (move.ComboPressed[0].Equals(move.Combo[0].ToString())) { if (!move._IsInCoroutine) { if (debug) { Debug.Log("starting coroutine"); } StartCoroutine(move.CombatSequnce(Time.time)); } } } if (move.ComboActivated) { //if you have queued up a move, then try to use another move during the delay period //add in baseDelay if (!isDelayCoRoutineRunning && !isDelayFinished) { StartCoroutine(WaitForDelay(move.ExciteDelay)); } else if (isDelayCoRoutineRunning) { continue; } if (debug) { Debug.Log(isDelayFinished); } if (isDelayFinished) { if (name == "Player") { if (PlayerMovement.inControl(true)) { //reset the path so that it stops calculating PlayerMovement.agent.ResetPath(); } } else { if (PlayerMovement.inControl(false)) { //reset the path so that it stops calculating PlayerMovement.agent.ResetPath(); } } currentTierPlaying = move; combatAnimationInitiated = true; //set the combat to true so the animation goes straight from run -> combat //anim.SetBool(isCombat, true); //set the speed to zero which implies no more movement therefore no more running PlayerMovement.agent.velocity = Vector3.zero; anim.SetTrigger(move.AnimationHash); //clears all combo pressed tierList.ForEach(x => x.ComboPressed.Clear()); //print("MOVE EXPANSION RATE: " + move.ExpansionRate); break; } else { //this block is when we are in the delay phase } } if (move.ComboPressed.Count > 0) { //they are in mid-keypress of a combo } } //foreach move if (combatAnimationInitiated && stateInfo.IsName(currentTierPlaying.AnimationStateName)) { if (debug) { Debug.Log("Animation has begun playing"); } animationPlayed = true; } if (combatAnimationInitiated && animationPlayed) { StartCoroutine(SphereWithTime(currentTierPlaying.ExpansionRate)); isAnimationFinished = true; //while playing animation for (int x = 0; x < tierList.Count; x++) { if (tierList[x].ComboActivated) { //reset all variables //anim.ResetTrigger(tierList[x].AnimationHash); //anim.SetBool(isCombat, false); combatAnimationInitiated = false; animationPlayed = false; tierList[x].ComboActivated = false; tierList[x]._IsComboFinished = false; isDelayFinished = false; } }//iterate tierList skipMoveCombinationCheck = false; ResetAllCombatTriggers(); }//stop combat }