Skip to content
This repository has been archived by the owner on Mar 9, 2024. It is now read-only.

Commit

Permalink
Add Attack Movement
Browse files Browse the repository at this point in the history
  • Loading branch information
Kassout committed Apr 26, 2023
1 parent add3a77 commit ec9f635
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,34 @@ AnimationClip:
m_HasGenericRootTransform: 0
m_HasMotionFloatCurves: 0
m_Events:
- time: 0.06666667
functionName: AnimationStartMovementTrigger
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0
- time: 0.06666667
functionName: AnimationTurnOffFlipTrigger
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0
- time: 0.2
functionName: AnimationStopMovementTrigger
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0
- time: 0.26666668
functionName: AnimationTrunOnFlipTrigger
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0
- time: 0.33333334
functionName: AnimationFinishTrigger
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,34 @@ AnimationClip:
m_HasGenericRootTransform: 0
m_HasMotionFloatCurves: 0
m_Events:
- time: 0.06666667
functionName: AnimationStartMovementTrigger
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0
- time: 0.06666667
functionName: AnimationTurnOffFlipTrigger
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0
- time: 0.2
functionName: AnimationStopMovementTrigger
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0
- time: 0.26666668
functionName: AnimationTrunOnFlipTrigger
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0
- time: 0.33333334
functionName: AnimationFinishTrigger
data:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,34 @@ AnimationClip:
m_HasGenericRootTransform: 0
m_HasMotionFloatCurves: 0
m_Events:
- time: 0.06666667
functionName: AnimationStartMovementTrigger
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0
- time: 0.06666667
functionName: AnimationTurnOffFlipTrigger
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0
- time: 0.2
functionName: AnimationStopMovementTrigger
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0
- time: 0.26666668
functionName: AnimationTrunOnFlipTrigger
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0
- time: 0.33333334
functionName: AnimationFinishTrigger
data:
Expand Down
8 changes: 8 additions & 0 deletions PlatformerController/Assets/Data/Weapons.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions PlatformerController/Assets/Data/Weapons/SwordData.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 04aafc5ec35034941bb80fe99b1f925a, type: 3}
m_Name: SwordData
m_EditorClassIdentifier:
movementSpeed:
- 3
- 4
- 2
8 changes: 8 additions & 0 deletions PlatformerController/Assets/Data/Weapons/SwordData.asset.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions PlatformerController/Assets/Scenes/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: f76bcdf370a40c346b14e7917c47dea9, type: 3}
m_Name:
m_EditorClassIdentifier:
weaponData: {fileID: 11400000, guid: 348c44c3fa52c50439d4a4275d846945, type: 2}
--- !u!1 &1258763309
GameObject:
m_ObjectHideFlags: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,24 @@ private void AnimationFinishTrigger()
{
_weapon.AnimationFinishTrigger();
}

private void AnimationStartMovementTrigger()
{
_weapon.AnimationStartMovementTrigger();
}

private void AnimationStopMovementTrigger()
{
_weapon.AnimationStopMovementTrigger();
}

private void AnimationTurnOffFlipTrigger()
{
_weapon.AnimationTurnOffFlipTrigger();
}

private void AnimationTrunOnFlipTrigger()
{
_weapon.AnimationTurnOnFlipTrigger();
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
public class PlayerAttackState : PlayerAbilityState
{
private Weapon _weapon;
private bool _setVelocity;
private bool _shouldCheckFlip;

private int _xInput;

private float _velocityToSet;

private Weapon _weapon;

public PlayerAttackState(Player player, PlayerStateMachine stateMachine, PlayerData playerData,
string animationBoolName)
: base(player, stateMachine, playerData, animationBoolName) {}

public override void Enter()
{
base.Enter();

_setVelocity = false;

_weapon.EnterWeapon();
}
Expand All @@ -20,12 +29,42 @@ public override void Exit()
_weapon.ExitWeapon();
}

public override void LogicUpdate()
{
base.LogicUpdate();

_xInput = _player.InputHandler.NormalizedInputX;

if (_shouldCheckFlip)
{
_player.CheckIfShouldFlip(_xInput);
}

if (_setVelocity)
{
_player.SetVelocityX(_velocityToSet * _player.FacingDirection);
}
}

public void SetWeapon(Weapon weapon)
{
_weapon = weapon;
_weapon.InitializeWeapon(this);
}

public void SetPlayerVelocity(float velocity)
{
_player.SetVelocityX(velocity * _player.FacingDirection);

_velocityToSet = velocity;
_setVelocity = true;
}

public void SetFlipCheck(bool value)
{
_shouldCheckFlip = value;
}

#region Animation Triggers

public override void AnimationFinishTrigger()
Expand Down
8 changes: 8 additions & 0 deletions PlatformerController/Assets/Scripts/ScriptableObjects.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using UnityEngine;

[CreateAssetMenu(fileName = "newWeaponData", menuName = "Data/Weapon Data/Weapon")]
public class WeaponData : ScriptableObject
{
public float[] movementSpeed;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions PlatformerController/Assets/Scripts/Weapons/Weapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

public class Weapon : MonoBehaviour
{
[SerializeField] private WeaponData weaponData;

protected int _attackCounter;

protected Animator _baseAnimator;
protected Animator _weaponAnimator;

Expand All @@ -23,15 +27,25 @@ public void InitializeWeapon(PlayerAttackState state)
public virtual void EnterWeapon()
{
gameObject.SetActive(true);

if (_attackCounter >= weaponData.movementSpeed.Length)
{
_attackCounter = 0;
}

_baseAnimator.SetBool("attack", true);
_weaponAnimator.SetBool("attack", true);

_baseAnimator.SetInteger("attackCounter", _attackCounter);
_weaponAnimator.SetInteger("attackCounter", _attackCounter);
}

public virtual void ExitWeapon()
{
_baseAnimator.SetBool("attack", false);
_weaponAnimator.SetBool("attack", false);

_attackCounter++;

gameObject.SetActive(false);
}
Expand All @@ -43,5 +57,25 @@ public virtual void AnimationFinishTrigger()
_state.AnimationFinishTrigger();
}

public virtual void AnimationStartMovementTrigger()
{
_state.SetPlayerVelocity(weaponData.movementSpeed[_attackCounter]);
}

public virtual void AnimationStopMovementTrigger()
{
_state.SetPlayerVelocity(0);
}

public virtual void AnimationTurnOffFlipTrigger()
{
_state.SetFlipCheck(false);
}

public virtual void AnimationTurnOnFlipTrigger()
{
_state.SetFlipCheck(true);
}

#endregion
}

0 comments on commit ec9f635

Please sign in to comment.