// Update is called once per frame void Update() { // Update timers m_AttackTimer -= Time.deltaTime; // Update combo m_ComboTracker.Update(Time.deltaTime); if (!m_Controller.isAttacking && m_AttackTimer < 0) { //m_Attack = 0; m_AttackType = AttackType.None; } bool triggerDown = false; if (IsAlive()) { // Gather input if (!m_Controller.IsImmobilized()) { m_Controller.SetInputVecX(Input.GetAxis("Horizontal")); m_Controller.SetInputVecY(Input.GetAxis("Vertical")); } else { m_Controller.SetInputVec(0, 0); } m_InputCameraVec.x = Input.GetAxis("RstickX"); m_InputCameraVec.y = Input.GetAxis("RstickY"); if ((m_Controller.IsGrounded() || !m_Controller.hasDoubleJumped || m_Controller.IsWalledL() || m_Controller.IsWalledR())) // TODO: Move to CharController maybe { m_Controller.inputJump = Input.GetButtonDown("Jump") ? true : m_Controller.inputJump; } triggerDown = Input.GetAxis("Trigger") < -0.25f; m_Controller.inputDodge = (triggerDown && !m_WasTriggerDown) || Input.GetButtonDown("Dodge") ? true : m_Controller.inputDodge; m_Controller.inputAttackL = Input.GetButtonDown("Fire1") ? true : m_Controller.inputAttackL; m_Controller.inputAttackH = Input.GetButtonDown("Fire2") ? true : m_Controller.inputAttackH; bool inputUp = Input.GetAxis("Vertical") > 0.5; bool inputDown = Input.GetAxis("Vertical") < -0.5; bool inputRight = Input.GetAxis("Horizontal") > 0.5; bool inputLeft = Input.GetAxis("Horizontal") < -0.5; if (inputUp && !m_InputUpPrev) { m_ComboTracker.StackInput(CombatInput.Up); } if (inputDown && !m_InputDownPrev) { m_ComboTracker.StackInput(CombatInput.Down); } if (inputRight && !m_InputRightPrev) { m_ComboTracker.StackInput(CombatInput.Right); } if (inputLeft && !m_InputLeftPrev) { m_ComboTracker.StackInput(CombatInput.Left); } m_InputUpPrev = inputUp; m_InputDownPrev = inputDown; m_InputRightPrev = inputRight; m_InputLeftPrev = inputLeft; // Update mashing speed if (Input.GetButtonDown("Fire1") && m_Controller.isAttacking) { m_MashSpeed = Mathf.Lerp(m_MashSpeed, 5, .25f); } else if (m_Controller.isAttacking) { m_MashSpeed = Mathf.Lerp(m_MashSpeed, 1, Time.deltaTime / m_MashDecay); } else { m_MashSpeed = 1; } } // Update sprite facing direction m_Renderer.flipX = !m_Controller.IsFacingRight(); m_WasTriggerDown = triggerDown; }
void Update() { m_ThinkTimer -= Time.deltaTime; if (m_ThinkTimer <= 0 && IsAlive() && !m_Controller.IsImmobilized()) { Think(); m_ThinkTimer = m_ThinkInterval; } // Knockdown recovery if (IsAlive() && m_Controller.isFalling) { if (m_Controller.IsGrounded()) { m_KnockdownTimer -= Time.deltaTime; } else { m_KnockdownTimer = m_KnockdownDuration; } if (m_KnockdownTimer <= 0) { // Recover m_Controller.isFalling = false; m_Tile.Flash(new Color(1, 1, 0, 0.15f), 0.25f); } } // Movement / attacking if (m_Target && IsAlive() && !m_Controller.IsImmobilized() && !m_Controller.isAttacking) { // Can attack check if (m_AttackTimer <= 0 && Vector3.Distance(transform.position, m_Target.transform.position) < m_StoppingDistance) { Attack(); } else { m_AttackTimer -= Time.deltaTime; // Anticipate target position var anticipator = m_Target.GetComponent <PositionAnticipator>(); //var anticipatedPosition = anticipator ? anticipator.GetAnticipatiedPosition() : m_Target.position; var anticipatedPosition = m_Target.transform.position; float xDist = anticipatedPosition.x - transform.position.x; // Don't continuously run into a wall like an idiot if (xDist < 0 && m_Controller.IsWalledL() || xDist > 0 && m_Controller.IsWalledR()) { xDist = 0; } bool aboveTarget = transform.position.y > anticipatedPosition.y + 0.1f; if (Mathf.Abs(xDist) > m_StoppingDistance) { // I would like to move towards my target if (xDist < 0 && m_Controller.IsGroundedL() || xDist > 0 && m_Controller.IsGroundedR() || aboveTarget && m_OnEdgeAbove == EdgeBehaviour.Cross || !aboveTarget && m_OnEdgeBelow == EdgeBehaviour.Cross ) // Edge cross check { m_Controller.SetInputVecX(xDist); } else { if (aboveTarget && m_OnEdgeAbove == EdgeBehaviour.Stop || !aboveTarget && m_OnEdgeBelow == EdgeBehaviour.Stop ) // Edge stop check { m_Controller.SetInputVecX(0); } else if (aboveTarget && m_OnEdgeAbove == EdgeBehaviour.Jump || !aboveTarget && m_OnEdgeBelow == EdgeBehaviour.Jump ) // Edge jump check { m_Controller.SetInputVecX(xDist); if (m_Controller.IsGrounded()) // TODO: Move to CharController maybe { m_Controller.inputJump = true; } } } } else { m_Controller.SetInputVecX(0); } } } // Update sprite facing direction if (IsAlive() && !m_Controller.isFalling) { m_Renderer.flipX = m_Controller.IsFacingRight(); } }