From c0a2df16b5828eab814c14e43913034b0aaa55c0 Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 21 Jul 2022 17:13:12 -0400 Subject: [PATCH] special attack on both buttons --- .gitignore | 4 + .../PlayerController.controller | 114 +++++++++--------- .../Resources/InputManager.prefab | 4 +- .../Scripts/Player/PlayerCombat.cs | 45 +++++-- .../Scripts/Player/PlayerMovement.cs | 30 +++-- .../Characters/dorothy/Dorothy Prefab.prefab | 11 +- 6 files changed, 126 insertions(+), 82 deletions(-) diff --git a/.gitignore b/.gitignore index 8c2e7c3..3b52266 100644 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,7 @@ crashlytics-build.properties /[Aa]ssets/[Ss]treamingAssets/aa.meta /[Aa]ssets/[Ss]treamingAssets/aa/* +unity_project/Library +unity_project/Logs +unity_project/Temp +unity_project/obj diff --git a/unity_project/Assets/BeatEmUp_GameTemplate3D/AnimationControllers/PlayerController.controller b/unity_project/Assets/BeatEmUp_GameTemplate3D/AnimationControllers/PlayerController.controller index 860d7cf..53bb092 100644 --- a/unity_project/Assets/BeatEmUp_GameTemplate3D/AnimationControllers/PlayerController.controller +++ b/unity_project/Assets/BeatEmUp_GameTemplate3D/AnimationControllers/PlayerController.controller @@ -25,28 +25,6 @@ AnimatorStateTransition: m_InterruptionSource: 0 m_OrderedInterruption: 1 m_CanTransitionToSelf: 0 ---- !u!1101 &-5206101775321413371 -AnimatorStateTransition: - m_ObjectHideFlags: 1 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: - m_Conditions: [] - m_DstStateMachine: {fileID: 0} - m_DstState: {fileID: 110244858} - m_Solo: 0 - m_Mute: 0 - m_IsExit: 0 - serializedVersion: 3 - m_TransitionDuration: 0.25 - m_TransitionOffset: 0 - m_ExitTime: 0 - m_HasExitTime: 1 - m_HasFixedDuration: 0 - m_InterruptionSource: 0 - m_OrderedInterruption: 1 - m_CanTransitionToSelf: 1 --- !u!91 &9100000 AnimatorController: m_ObjectHideFlags: 0 @@ -61,205 +39,205 @@ AnimatorController: m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: JumpKickActive m_Type: 4 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: JumpKick m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Punch1 m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Punch2 m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Punch3 m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Defend m_Type: 4 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Hit1 m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Hit2 m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Kick0 m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Kick1 m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Kick2 m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: GroundPunch m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: GroundKick m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Pickup m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Run m_Type: 4 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Walk m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Idle m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: JumpInProgress m_Type: 4 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Falling m_Type: 4 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: MovementSpeed m_Type: 1 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: Death m_Type: 4 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: KnockDown_Up m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: KnockDown_Down m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: KnockDown_End m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: StandUp m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: isGrounded m_Type: 4 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: JumpUp m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: ThrowWeapon m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: FireGun m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: SwingWeapon m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: RunningPunch m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: RunningKick m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} - m_Name: TornadoKick m_Type: 9 m_DefaultFloat: 0 m_DefaultInt: 0 m_DefaultBool: 0 - m_Controller: {fileID: 0} + m_Controller: {fileID: 9100000} m_AnimatorLayers: - serializedVersion: 5 m_Name: Base Layer @@ -2855,6 +2833,28 @@ AnimatorState: m_MirrorParameter: m_CycleOffsetParameter: m_TimeParameter: +--- !u!1101 &1424379873004975657 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: [] + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: 1102332405851808462} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0.25 + m_TransitionOffset: 0 + m_ExitTime: 0.8076923 + m_HasExitTime: 1 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 --- !u!1102 &5679427123164778674 AnimatorState: serializedVersion: 6 @@ -2866,7 +2866,7 @@ AnimatorState: m_Speed: 2 m_CycleOffset: 0 m_Transitions: - - {fileID: -5206101775321413371} + - {fileID: 1424379873004975657} m_StateMachineBehaviours: [] m_Position: {x: 50, y: 50, z: 0} m_IKOnFeet: 1 diff --git a/unity_project/Assets/BeatEmUp_GameTemplate3D/Resources/InputManager.prefab b/unity_project/Assets/BeatEmUp_GameTemplate3D/Resources/InputManager.prefab index e6e1d2e..2b319ec 100644 --- a/unity_project/Assets/BeatEmUp_GameTemplate3D/Resources/InputManager.prefab +++ b/unity_project/Assets/BeatEmUp_GameTemplate3D/Resources/InputManager.prefab @@ -73,9 +73,9 @@ MonoBehaviour: - Action: Punch inputType: 0 key: 331 - - Action: Kick + - Action: inputType: 0 - key: 332 + key: 0 - Action: Defend inputType: 0 key: 333 diff --git a/unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/Player/PlayerCombat.cs b/unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/Player/PlayerCombat.cs index 6067b6d..c19ec4d 100644 --- a/unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/Player/PlayerCombat.cs +++ b/unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/Player/PlayerCombat.cs @@ -267,19 +267,23 @@ public class PlayerCombat : MonoBehaviour, IDamagable { } } - //jump punch + //special attack (both) + if (action == "Punch" && buttonState == BUTTONSTATE.PRESS) { + + var pm = GetComponent(); + if (pm != null && (pm.JumpNextFixedUpdate || (pm.jumpInProgress && pm.JumpIsRecent()))) + { + DoSpecialAttack(pm); + Debug.Log("did special attack"); + return; + } + } + + //jump kick (using punch button) if (action == "Punch" && buttonState == BUTTONSTATE.PRESS && !isGrounded) { - if(JumpKickData.animTrigger.Length > 0) { - doAttack(JumpKickData, UNITSTATE.JUMPKICK, "Kick"); - StartCoroutine(JumpKickInProgress()); - } - return; - } - - //jump kick - if (action == "Kick" && buttonState == BUTTONSTATE.PRESS && !isGrounded) { if(JumpKickData.animTrigger.Length > 0) { - doAttack(JumpKickData, UNITSTATE.JUMPKICK, "Kick"); + Debug.Log("did jump kick"); + doAttack(JumpKickData, UNITSTATE.JUMPKICK, "Kick"); StartCoroutine(JumpKickInProgress()); } return; @@ -311,10 +315,24 @@ public class PlayerCombat : MonoBehaviour, IDamagable { } } + + public void DoSpecialAttack(PlayerMovement pm) + { + pm.CancelJump(); + pm.JumpNextFixedUpdate = false; + pm.SetDirection(currentDirection); + doAttack(KickCombo[0], UNITSTATE.KICK, "Kick"); + return; + } #endregion #region Combat functions + public bool IsPunching() + { + return playerState.currentState == UNITSTATE.PUNCH; + } + private void doAttack(DamageObject damageObject, UNITSTATE state, string inputAction){ animator.SetAnimatorTrigger(damageObject.animTrigger); playerState.SetState(state); @@ -335,6 +353,11 @@ public class PlayerCombat : MonoBehaviour, IDamagable { if(state == UNITSTATE.JUMPKICK) return; Invoke ("Ready", damageObject.duration); } + public const float SIMULTANEOUS_BUTTON_SPACING = .03f; + public bool AttackIsRecent() + { + return lastAttackTime > Time.time - PlayerCombat.SIMULTANEOUS_BUTTON_SPACING; + } //use the currently equipped weapon void useCurrentWeapon(){ diff --git a/unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/Player/PlayerMovement.cs b/unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/Player/PlayerMovement.cs index b65465d..8f95c7b 100644 --- a/unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/Player/PlayerMovement.cs +++ b/unity_project/Assets/BeatEmUp_GameTemplate3D/Scripts/Player/PlayerMovement.cs @@ -38,11 +38,12 @@ public class PlayerMovement : MonoBehaviour { public bool jumpInProgress; private bool isDead = false; - private bool JumpNextFixedUpdate; + public bool JumpNextFixedUpdate; private float jumpDownwardsForce = .3f; + private float lastJumpTime = 0f; - //a list of states where movement can take place - private List MovementStates = new List { + //a list of states where movement can take place + private List MovementStates = new List { UNITSTATE.IDLE, UNITSTATE.WALK, UNITSTATE.RUN, @@ -175,6 +176,7 @@ public class PlayerMovement : MonoBehaviour { JumpNextFixedUpdate = false; jumpInProgress = true; rb.velocity = Vector3.up * JumpForce; + lastJumpTime = Time.time; //play animation animator.SetAnimatorBool("JumpInProgress", true); @@ -222,14 +224,28 @@ public class PlayerMovement : MonoBehaviour { if(doubleTapActive && IsGrounded() && Mathf.Abs(dir.x)>0) playerState.SetState(UNITSTATE.RUN); } + public bool JumpIsRecent() + { + return lastJumpTime > Time.time - PlayerCombat.SIMULTANEOUS_BUTTON_SPACING; + } + //input actions void OnInputEvent(string action, BUTTONSTATE buttonState) { - //ignore input when we are dead or when this state is not active - if(!MovementStates.Contains(playerState.currentState) || isDead) return; + //special attack (jump + attack) if jump is hit second + PlayerCombat pc = GetComponent(); + if (action == "Jump" && buttonState == BUTTONSTATE.PRESS && playerState.currentState == UNITSTATE.PUNCH && pc.AttackIsRecent()) + { + pc.DoSpecialAttack(this); + } - //start a jump - if(action == "Jump" && buttonState == BUTTONSTATE.PRESS && IsGrounded() && playerState.currentState != UNITSTATE.JUMPING) JumpNextFixedUpdate = true; + //ignore input when we are dead or when this state is not active + if (!MovementStates.Contains(playerState.currentState) || isDead) + return; + + + + if (action == "Jump" && buttonState == BUTTONSTATE.PRESS && IsGrounded() && playerState.currentState != UNITSTATE.JUMPING) JumpNextFixedUpdate = true; //start running when a run button is pressed (e.g. Joypad controls) if(action == "Run") playerState.SetState(UNITSTATE.RUN); diff --git a/unity_project/Assets/Characters/dorothy/Dorothy Prefab.prefab b/unity_project/Assets/Characters/dorothy/Dorothy Prefab.prefab index df9b658..b5cd198 100644 --- a/unity_project/Assets/Characters/dorothy/Dorothy Prefab.prefab +++ b/unity_project/Assets/Characters/dorothy/Dorothy Prefab.prefab @@ -130,6 +130,7 @@ MonoBehaviour: currentDirection: -1 inputDirection: {x: 0, y: 0} jumpInProgress: 0 + JumpNextFixedUpdate: 0 --- !u!114 &4799662874652314383 MonoBehaviour: m_ObjectHideFlags: 0 @@ -227,7 +228,7 @@ MonoBehaviour: knockBackForce: 0 hitSFX: DefaultHit knockDown: 1 - slowMotionEffect: 1 + slowMotionEffect: 0 DefenceOverride: 1 isGroundAttack: 0 animationClip: {fileID: 0} @@ -284,8 +285,8 @@ MonoBehaviour: knockBackForce: 5 hitSFX: HeavyHit knockDown: 1 - slowMotionEffect: 1 - DefenceOverride: 1 + slowMotionEffect: 0 + DefenceOverride: 0 isGroundAttack: 0 animationClip: {fileID: 0} animationSpeed: 0 @@ -303,8 +304,8 @@ MonoBehaviour: knockBackForce: 5 hitSFX: HeavyHit knockDown: 1 - slowMotionEffect: 1 - DefenceOverride: 1 + slowMotionEffect: 0 + DefenceOverride: 0 isGroundAttack: 0 animationClip: {fileID: 0} animationSpeed: 0