private void AttackInputCallback(InputAction.CallbackContext ctx) { ButtonControl button = ctx.control as ButtonControl; if (!button.wasPressedThisFrame) { return; } if (m_PlayerStance == null) { return; } if (!m_PlayerStance.IsCombatStance()) { AudioManager.m_Instance.PlaySoundAtPosition("GEN_Weapon_Draw", transform.position); m_PlayerStance.SetStance(PlayerStance.Stance.STANCE_TWOHANDED); return; } if (!m_PlayerStance.CanPerformAction(PlayerStance.Action.ACTION_ATTACK)) { return; } m_AttackedInCurrentFrame = true; }
//key bindings public void UseSkillAt(InputAction.CallbackContext ctx) { if (!m_PlayerStance.CanPerformAction(PlayerStance.Action.ACTION_CASTSPELL)) { return; } ButtonControl button = ctx.control as ButtonControl; if (!button.wasPressedThisFrame) { return; } if (m_ItemSkillSlots.Count == 0) { return; } if (m_PlayerStance == null) { return; } SkillItem currentSkill = m_ItemSkillSlots.Peek(); if (currentSkill.IsGroundOnlySpell()) { if (!m_PlayerStance.CanPerformAction(PlayerStance.Action.ACTION_CASTSPELL)) { return; } } // Player must draw his weapon before spell cast if (!m_PlayerStance.GetWeaponTransform().gameObject.activeInHierarchy) { return; } currentSkill.UseSkill(this.transform); m_CurrentActiveSkill = currentSkill.GetSkillType(); m_CastInCurrentFrame = true; currentSkill.DecrementUses(); if (currentSkill.HasNoMoreUses()) { RemoveSkill(); } }
private void ComputeXZAxisVelocity() { // If the player is not allowed to walk, don't. if (!m_PlayerStance.CanPerformAction(PlayerStance.Action.ACTION_WALK)) { m_MovementParams.m_Velocity.x = Mathf.Lerp(m_MovementParams.m_Velocity.x, 0, Time.deltaTime * 5); m_MovementParams.m_Velocity.z = Mathf.Lerp(m_MovementParams.m_Velocity.z, 0, Time.deltaTime * 5); return; } Vector2 inputXZ = GetInputAxis(); // This is to fix not being able to walk forward when the camera is looking down Vector3 cameraForward = Camera.main.transform.forward; cameraForward.y = 0; cameraForward.Normalize(); Vector3 xzVelocity = Camera.main.transform.right * inputXZ[0] + cameraForward * inputXZ[1]; xzVelocity *= m_MovementParams.m_MoveSpeed; xzVelocity.y = 0; // Slow the player down when walking backwards or side to side if (m_PlayerStance.IsCombatStance() && !IsMovingForward()) { xzVelocity *= m_MovementParams.m_NonForwardMovePenalty.Evaluate(Mathf.Abs(VelocityDotForward())); } // Slow the player down when blocking if (m_PlayerCombatHandler.IsBlocking()) { xzVelocity *= (1 - m_MovementParams.m_BlockMovePenalty); } // Add external modifier; xzVelocity.Scale(m_MovementParams.m_ExternalVelocityModifier); // Update movement params so other system can use this final value. m_MovementParams.m_Velocity.x = xzVelocity.x; m_MovementParams.m_Velocity.z = xzVelocity.z; }