浏览代码

Update PigChef TransitionTable, Jumping and Sliding mechanics (#310)

* Update PigChef_TransitionTable.asset

Changes:
- From Idle
  - To Sliding
    - ~~IsActuallyMoving~~
  - To JumpAscending
     - ~~IsSliding~~
- From Walking
  - **To Sliding (moved above To JumpAscending)**
  - To JumpAscending
    - ~~IsSliding~~

* Reordered Walking and Idle states transitions.

- To Sliding
- To JumpAscending
- To JumpDescending
- To Attack
- To PickUp
- To Talk
- To Walking/Idle

* Update PigChef.controller

Updated PigChef Animator controller to reflect the changes to the TransitionTable:
- Added transition from Walking to Collect on PickUp trigger.
- Added transition from Walking to Talking when IsTalking is True.

* Added MidSliding State

The MidSliding State is added to prevent the state machine from going back and forth between Sliding and JumpDescending when not needed.

* Major changes to player sliding and aerial movement, bug fixes, and adjustments...
/devlogs-3-input
GitHub 3 年前
当前提交
71fe0c78
共有 28 个文件被更改,包括 420 次插入135 次删除
  1. 52
      UOP1_Project/Assets/Art/Characters/PigChef/Animation/PigChef.controller
  2. 136
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/PigChef_TransitionTable.asset
  3. 1
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/States/Idle.asset
  4. 2
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/States/JumpAscending.asset
  5. 2
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/States/JumpDescending.asset
  6. 1
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/States/Sliding.asset
  7. 21
      UOP1_Project/Assets/Scripts/Characters/Protagonist.cs
  8. 1
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/ApplyMovementVectorActionSO.cs
  9. 9
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/AscendActionSO.cs
  10. 7
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/DescendActionSO.cs
  11. 28
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/SlideActionSO.cs
  12. 5
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsMovingConditionSO.cs
  13. 16
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/AerialMovement.asset
  14. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/AerialMovement.asset.meta
  15. 15
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/StopMovement_OnEnter.asset
  16. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/StopMovement_OnEnter.asset.meta
  17. 16
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Conditions/Timer_SlidingCheck.asset
  18. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Conditions/Timer_SlidingCheck.asset.meta
  19. 18
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/States/MidSliding.asset
  20. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/States/MidSliding.asset.meta
  21. 81
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/AerialMovementActionSO.cs
  22. 11
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/AerialMovementActionSO.cs.meta
  23. 44
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/StopMovementActionSO.cs
  24. 11
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/StopMovementActionSO.cs.meta
  25. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/MoveInTheAir.asset.meta
  26. 15
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/GravitySliding.asset
  27. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/GravitySliding.asset.meta
  28. 15
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/MoveInTheAir.asset

52
UOP1_Project/Assets/Art/Characters/PigChef/Animation/PigChef.controller


m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &-6490502190932390817
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: IsTalking
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: -5136259595334157278}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.3
m_TransitionOffset: 0
m_ExitTime: 0.70000005
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &-6362113396495685685
AnimatorStateTransition:
m_ObjectHideFlags: 1

- {fileID: 7941493872309352012}
- {fileID: 3525189850006141372}
- {fileID: -8057009673609800356}
- {fileID: 5684728565472367712}
- {fileID: -6490502190932390817}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0

m_TransitionDuration: 0.1
m_TransitionOffset: 0
m_ExitTime: 0.98747915
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &5684728565472367712
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
m_ConditionEvent: PickUp
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 2346626782594886847}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.1
m_TransitionOffset: 0
m_ExitTime: 0.8161291
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0

136
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/PigChef_TransitionTable.asset


m_EditorClassIdentifier:
_transitions:
- FromState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
ToState: {fileID: 11400000, guid: 027d32476800b3543b2f5446a59054c8, type: 2}
ToState: {fileID: 11400000, guid: 4c2c0dc4f7ee62b4d95b20ac3dce281e, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: c5090b215e4f1594f9d1ef6680cd15bb, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
ToState: {fileID: 11400000, guid: 0aa906b71b1b4504d950f5ee8e1f06e8, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 620f4efd93744084a8ac9ba272f093dc, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 027d32476800b3543b2f5446a59054c8, type: 2}
ToState: {fileID: 11400000, guid: 4c2c0dc4f7ee62b4d95b20ac3dce281e, type: 2}
Condition: {fileID: 11400000, guid: a79b812272ab8314aa305b39f9a2740a, type: 2}
Condition: {fileID: 11400000, guid: c5090b215e4f1594f9d1ef6680cd15bb, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 027d32476800b3543b2f5446a59054c8, type: 2}
ToState: {fileID: 11400000, guid: 0aa906b71b1b4504d950f5ee8e1f06e8, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 620f4efd93744084a8ac9ba272f093dc, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 0aa906b71b1b4504d950f5ee8e1f06e8, type: 2}
ToState: {fileID: 11400000, guid: c57ed1dc57a890943b2648ca8a581075, type: 2}

Condition: {fileID: 11400000, guid: a79b812272ab8314aa305b39f9a2740a, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 027d32476800b3543b2f5446a59054c8, type: 2}
ToState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
ToState: {fileID: 11400000, guid: c57ed1dc57a890943b2648ca8a581075, type: 2}
Condition: {fileID: 11400000, guid: a79b812272ab8314aa305b39f9a2740a, type: 2}
Condition: {fileID: 11400000, guid: c7258bdb2558a214f916c8b5b3c0fa1f, type: 2}
ToState: {fileID: 11400000, guid: 0aa906b71b1b4504d950f5ee8e1f06e8, type: 2}
ToState: {fileID: 11400000, guid: bda8bfafdf35e3e4092bb96279d4894c, type: 2}
Condition: {fileID: 11400000, guid: 620f4efd93744084a8ac9ba272f093dc, type: 2}
Condition: {fileID: 11400000, guid: ac445a33a0d072a4b96458c8ea343d49, type: 2}
- FromState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
ToState: {fileID: 11400000, guid: c57ed1dc57a890943b2648ca8a581075, type: 2}
Conditions:
Condition: {fileID: 11400000, guid: c5090b215e4f1594f9d1ef6680cd15bb, type: 2}
Condition: {fileID: 11400000, guid: c7258bdb2558a214f916c8b5b3c0fa1f, type: 2}
- FromState: {fileID: 11400000, guid: 027d32476800b3543b2f5446a59054c8, type: 2}
ToState: {fileID: 11400000, guid: 4c2c0dc4f7ee62b4d95b20ac3dce281e, type: 2}
- FromState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
ToState: {fileID: 11400000, guid: bda8bfafdf35e3e4092bb96279d4894c, type: 2}
Condition: {fileID: 11400000, guid: ac445a33a0d072a4b96458c8ea343d49, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 4c2c0dc4f7ee62b4d95b20ac3dce281e, type: 2}
ToState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
Conditions:
- ExpectedResult: 1
- FromState: {fileID: 11400000, guid: 027d32476800b3543b2f5446a59054c8, type: 2}
ToState: {fileID: 11400000, guid: c57ed1dc57a890943b2648ca8a581075, type: 2}
- FromState: {fileID: 11400000, guid: 4c2c0dc4f7ee62b4d95b20ac3dce281e, type: 2}
ToState: {fileID: 11400000, guid: 0aa906b71b1b4504d950f5ee8e1f06e8, type: 2}
Condition: {fileID: 11400000, guid: c7258bdb2558a214f916c8b5b3c0fa1f, type: 2}
Condition: {fileID: 11400000, guid: ddd205b8cff23bc48b47aa5538d549be, type: 2}
- FromState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
ToState: {fileID: 11400000, guid: 4c2c0dc4f7ee62b4d95b20ac3dce281e, type: 2}
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 620f4efd93744084a8ac9ba272f093dc, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 4c2c0dc4f7ee62b4d95b20ac3dce281e, type: 2}
ToState: {fileID: 11400000, guid: ecc888784b4f5fd4db9430a844819e2b, type: 2}
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: c7258bdb2558a214f916c8b5b3c0fa1f, type: 2}
Operator: 0
ToState: {fileID: 11400000, guid: 0aa906b71b1b4504d950f5ee8e1f06e8, type: 2}
ToState: {fileID: 11400000, guid: 78675b2bf031c3f4a9c28dda969298e2, type: 2}
Condition: {fileID: 11400000, guid: 620f4efd93744084a8ac9ba272f093dc, type: 2}
Condition: {fileID: 11400000, guid: 9c4a0f8b97247c643aef1b1284f21ebc, type: 2}
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: c5090b215e4f1594f9d1ef6680cd15bb, type: 2}
- FromState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
ToState: {fileID: 11400000, guid: ff92a93d8a8694247b507d811c88e402, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: b33fba8c83df19f4ead430fbcc728687, type: 2}
ToState: {fileID: 11400000, guid: c57ed1dc57a890943b2648ca8a581075, type: 2}
ToState: {fileID: 11400000, guid: 027d32476800b3543b2f5446a59054c8, type: 2}
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: c7258bdb2558a214f916c8b5b3c0fa1f, type: 2}
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: a79b812272ab8314aa305b39f9a2740a, type: 2}
- FromState: {fileID: 11400000, guid: 4c2c0dc4f7ee62b4d95b20ac3dce281e, type: 2}
- FromState: {fileID: 11400000, guid: ecc888784b4f5fd4db9430a844819e2b, type: 2}
- FromState: {fileID: 11400000, guid: 4c2c0dc4f7ee62b4d95b20ac3dce281e, type: 2}
- FromState: {fileID: 11400000, guid: ecc888784b4f5fd4db9430a844819e2b, type: 2}
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: ddd205b8cff23bc48b47aa5538d549be, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 4c2c0dc4f7ee62b4d95b20ac3dce281e, type: 2}
ToState: {fileID: 11400000, guid: c57ed1dc57a890943b2648ca8a581075, type: 2}
Conditions:
Condition: {fileID: 11400000, guid: c7258bdb2558a214f916c8b5b3c0fa1f, type: 2}
Operator: 0
- ExpectedResult: 0
- FromState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
ToState: {fileID: 11400000, guid: ff92a93d8a8694247b507d811c88e402, type: 2}
- FromState: {fileID: 11400000, guid: ecc888784b4f5fd4db9430a844819e2b, type: 2}
ToState: {fileID: 11400000, guid: c57ed1dc57a890943b2648ca8a581075, type: 2}
Condition: {fileID: 11400000, guid: b33fba8c83df19f4ead430fbcc728687, type: 2}
Condition: {fileID: 11400000, guid: b5cf328bcf17e41469fda079c80b3c84, type: 2}
Operator: 0
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: c7258bdb2558a214f916c8b5b3c0fa1f, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: ff92a93d8a8694247b507d811c88e402, type: 2}
ToState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}

Operator: 0
- FromState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
ToState: {fileID: 11400000, guid: 78675b2bf031c3f4a9c28dda969298e2, type: 2}
Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 9c4a0f8b97247c643aef1b1284f21ebc, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 78675b2bf031c3f4a9c28dda969298e2, type: 2}
ToState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
Conditions:

- FromState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
ToState: {fileID: 11400000, guid: bda8bfafdf35e3e4092bb96279d4894c, type: 2}
- FromState: {fileID: 11400000, guid: bda8bfafdf35e3e4092bb96279d4894c, type: 2}
ToState: {fileID: 11400000, guid: 027d32476800b3543b2f5446a59054c8, type: 2}
Condition: {fileID: 11400000, guid: ac445a33a0d072a4b96458c8ea343d49, type: 2}
Condition: {fileID: 11400000, guid: 373ff606aeb23834eb964bdf9a6f6e3c, type: 2}
Operator: 0
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: a79b812272ab8314aa305b39f9a2740a, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: bda8bfafdf35e3e4092bb96279d4894c, type: 2}
ToState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}

Condition: {fileID: 11400000, guid: a79b812272ab8314aa305b39f9a2740a, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 027d32476800b3543b2f5446a59054c8, type: 2}
ToState: {fileID: 11400000, guid: bda8bfafdf35e3e4092bb96279d4894c, type: 2}
ToState: {fileID: 11400000, guid: 78675b2bf031c3f4a9c28dda969298e2, type: 2}
Condition: {fileID: 11400000, guid: ac445a33a0d072a4b96458c8ea343d49, type: 2}
Condition: {fileID: 11400000, guid: 9c4a0f8b97247c643aef1b1284f21ebc, type: 2}
- FromState: {fileID: 11400000, guid: bda8bfafdf35e3e4092bb96279d4894c, type: 2}
ToState: {fileID: 11400000, guid: 027d32476800b3543b2f5446a59054c8, type: 2}
- FromState: {fileID: 11400000, guid: 027d32476800b3543b2f5446a59054c8, type: 2}
ToState: {fileID: 11400000, guid: ff92a93d8a8694247b507d811c88e402, type: 2}
Condition: {fileID: 11400000, guid: 373ff606aeb23834eb964bdf9a6f6e3c, type: 2}
Condition: {fileID: 11400000, guid: b33fba8c83df19f4ead430fbcc728687, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 027d32476800b3543b2f5446a59054c8, type: 2}
ToState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
Conditions:
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: a79b812272ab8314aa305b39f9a2740a, type: 2}
- FromState: {fileID: 11400000, guid: ecc888784b4f5fd4db9430a844819e2b, type: 2}
ToState: {fileID: 11400000, guid: 4c2c0dc4f7ee62b4d95b20ac3dce281e, type: 2}
Conditions:
Condition: {fileID: 11400000, guid: a79b812272ab8314aa305b39f9a2740a, type: 2}
Condition: {fileID: 11400000, guid: b5cf328bcf17e41469fda079c80b3c84, type: 2}
Operator: 0

1
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/States/Idle.asset


m_EditorClassIdentifier:
_actions:
- {fileID: 11400000, guid: c0d0573a78e4c6245ab9676e7af35880, type: 2}
- {fileID: 11400000, guid: bcf4edc006209d54da9cd4c18329bb43, type: 2}
- {fileID: 11400000, guid: bd85c54d16eb60c4c99504f1679af851, type: 2}
- {fileID: 11400000, guid: 47d9da417e68970419335f80f4395239, type: 2}

2
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/States/JumpAscending.asset


_actions:
- {fileID: 11400000, guid: 4984500e131bbe34594c4ab0e2c409f3, type: 2}
- {fileID: 11400000, guid: 00abdcc5c2b7e3d4d8855f1a84801fae, type: 2}
- {fileID: 11400000, guid: f1f9b67c2b957d74dae6555b3598ae49, type: 2}
- {fileID: 11400000, guid: b099300f484e1344487cc666f75825cc, type: 2}
- {fileID: 11400000, guid: 5d9c1bbe4ffcb2146a540998d17b665d, type: 2}
- {fileID: 11400000, guid: 47d9da417e68970419335f80f4395239, type: 2}
- {fileID: 11400000, guid: 096d532f9a47f3145892efa1c4322e72, type: 2}

2
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/States/JumpDescending.asset


m_Name: JumpDescending
m_EditorClassIdentifier:
_actions:
- {fileID: 11400000, guid: f1f9b67c2b957d74dae6555b3598ae49, type: 2}
- {fileID: 11400000, guid: b099300f484e1344487cc666f75825cc, type: 2}
- {fileID: 11400000, guid: 5d442cfcb78da8b418d6ae3e93e5748e, type: 2}
- {fileID: 11400000, guid: 47d9da417e68970419335f80f4395239, type: 2}
- {fileID: 11400000, guid: 096d532f9a47f3145892efa1c4322e72, type: 2}

1
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/States/Sliding.asset


_actions:
- {fileID: 11400000, guid: 99b804881a9d5744fb4784c30000c0b5, type: 2}
- {fileID: 11400000, guid: c0d0573a78e4c6245ab9676e7af35880, type: 2}
- {fileID: 11400000, guid: 088f3e34793299349983d53aaf39e5e3, type: 2}
- {fileID: 11400000, guid: 9e558dc250163db40a4e1f7241ee15c2, type: 2}
- {fileID: 11400000, guid: 47d9da417e68970419335f80f4395239, type: 2}
- {fileID: 11400000, guid: 4badb7afa3370ba4d8a229584c5c744f, type: 2}

21
UOP1_Project/Assets/Scripts/Characters/Protagonist.cs


private Vector2 _previousMovementInput;
//These fields are read and manipulated by the StateMachine actions
[HideInInspector] public bool jumpInput;
[HideInInspector] public bool extraActionInput;
[HideInInspector] public bool attackInput;
[HideInInspector] public Vector3 movementInput; //Initial input coming from the Protagonist script
[HideInInspector] public Vector3 movementVector; //Final movement vector, manipulated by the StateMachine actions
[HideInInspector] public ControllerColliderHit lastHit;
[HideInInspector] public bool isRunning; // Used when using the keyboard to run, brings the normalised speed to 1
[NonSerialized] public bool jumpInput;
[NonSerialized] public bool extraActionInput;
[NonSerialized] public bool attackInput;
[NonSerialized] public Vector3 movementInput; //Initial input coming from the Protagonist script
[NonSerialized] public Vector3 movementVector; //Final movement vector, manipulated by the StateMachine actions
[NonSerialized] public ControllerColliderHit lastHit;
[NonSerialized] public bool isRunning; // Used when using the keyboard to run, brings the normalised speed to 1
public const float GRAVITY_MULTIPLIER = 5f;
public const float MAX_FALL_SPEED = -50f;
public const float MAX_RISE_SPEED = 100f;
public const float GRAVITY_COMEBACK_MULTIPLIER = .03f;
public const float GRAVITY_DIVIDER = .6f;
public const float AIR_RESISTANCE = 5f;
private void OnControllerColliderHit(ControllerColliderHit hit)
{

1
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/ApplyMovementVectorActionSO.cs


public override void OnUpdate()
{
_characterController.Move(_protagonistScript.movementVector * Time.deltaTime);
_protagonistScript.movementVector = _characterController.velocity;
}
}

9
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/AscendActionSO.cs


private float _verticalMovement;
private float _gravityContributionMultiplier;
private const float GRAVITY_COMEBACK_MULTIPLIER = .03f;
private const float GRAVITY_DIVIDER = .6f;
private const float GRAVITY_MULTIPLIER = 5f;
private AscendActionSO _originSO => (AscendActionSO)base.OriginSO; // The SO this StateAction spawned from
public override void Awake(StateMachine stateMachine)

public override void OnUpdate()
{
_gravityContributionMultiplier += GRAVITY_COMEBACK_MULTIPLIER;
_gravityContributionMultiplier *= GRAVITY_DIVIDER; //Reduce the gravity effect
_verticalMovement += Physics.gravity.y * GRAVITY_MULTIPLIER * Time.deltaTime * _gravityContributionMultiplier;
_gravityContributionMultiplier += Protagonist.GRAVITY_COMEBACK_MULTIPLIER;
_gravityContributionMultiplier *= Protagonist.GRAVITY_DIVIDER; //Reduce the gravity effect
_verticalMovement += Physics.gravity.y * Protagonist.GRAVITY_MULTIPLIER * Time.deltaTime * _gravityContributionMultiplier;
//Note that even if it's added, the above value is negative due to Physics.gravity.y
_protagonistScript.movementVector.y = _verticalMovement;

7
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/DescendActionSO.cs


private Protagonist _protagonistScript;
private float _verticalMovement;
private const float GRAVITY_MULTIPLIER = 5f;
private const float MAX_FALL_SPEED = -50f;
private const float MAX_RISE_SPEED = 100f;
public override void Awake(StateMachine stateMachine)
{

public override void OnUpdate()
{
_verticalMovement += Physics.gravity.y * GRAVITY_MULTIPLIER * Time.deltaTime;
_verticalMovement += Physics.gravity.y * Protagonist.GRAVITY_MULTIPLIER * Time.deltaTime;
_verticalMovement = Mathf.Clamp(_verticalMovement, MAX_FALL_SPEED, MAX_RISE_SPEED);
_verticalMovement = Mathf.Clamp(_verticalMovement, Protagonist.MAX_FALL_SPEED, Protagonist.MAX_RISE_SPEED);
_protagonistScript.movementVector.y = _verticalMovement;
}

28
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/SlideActionSO.cs


using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "SlideAction", menuName = "State Machines/Actions/Slide")]
public class SlideActionSO : StateActionSO<SlideAction>
{
[Tooltip("Sliding speed on the XZ plane.")]
public float slideSpeed = 10f;
}
public class SlideActionSO : StateActionSO<SlideAction> { }
//Component references
private SlideActionSO _originSO => (SlideActionSO)base.OriginSO; // The SO this StateAction spawned from
public override void Awake(StateMachine stateMachine)
{

public override void OnUpdate()
{
Vector3 velocity = _protagonistScript.movementVector;
float speed = -Physics.gravity.y * Protagonist.GRAVITY_MULTIPLIER * Time.deltaTime;
_protagonistScript.movementVector.x = (1f - hitNormal.y) * hitNormal.x * _originSO.slideSpeed;
_protagonistScript.movementVector.z = (1f - hitNormal.y) * hitNormal.z * _originSO.slideSpeed;
}
var vector = new Vector3(hitNormal.x, -hitNormal.y, hitNormal.z);
Vector3.OrthoNormalize(ref hitNormal, ref vector);
public override void OnStateExit()
{
_protagonistScript.movementVector = Vector3.zero;
// Cheap way to avoid overshooting the character, which causes it to move away from the slope
if (Mathf.Sign(vector.x) == Mathf.Sign(velocity.x))
vector.x *= 0.5f;
if (Mathf.Sign(vector.z) == Mathf.Sign(velocity.z))
vector.z *= 0.5f;
velocity += vector * speed;
_protagonistScript.movementVector = velocity;
}
}

5
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsMovingConditionSO.cs


movementVector.y = 0f;
return movementVector.sqrMagnitude > _originSO.treshold;
}
public override void OnStateExit()
{
_protagonistScript.movementVector = Vector3.zero;
}
}

16
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/AerialMovement.asset


%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: 0b9ee5024e536a5418bbc4f7484673d7, type: 3}
m_Name: AerialMovement
m_EditorClassIdentifier:
_desiredSpeed: 7
_acceleration: 20

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/AerialMovement.asset.meta


fileFormatVersion: 2
guid: b099300f484e1344487cc666f75825cc
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

15
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/StopMovement_OnEnter.asset


%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: ba8fe96b9505e1946a0637c5ff7a3904, type: 3}
m_Name: StopMovement_OnEnter
m_EditorClassIdentifier:
_moment: 0

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/StopMovement_OnEnter.asset.meta


fileFormatVersion: 2
guid: bcf4edc006209d54da9cd4c18329bb43
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

16
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Conditions/Timer_SlidingCheck.asset


%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: 8139f9f328ed1144690b7a9ffca2d5b4, type: 3}
m_Name: Timer_SlidingCheck
m_EditorClassIdentifier:
cacheResult: 1
timerLength: 0.25

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Conditions/Timer_SlidingCheck.asset.meta


fileFormatVersion: 2
guid: b5cf328bcf17e41469fda079c80b3c84
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

18
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/States/MidSliding.asset


%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: 35432205b9a6a374bbbfe6b7cac92179, type: 3}
m_Name: MidSliding
m_EditorClassIdentifier:
_actions:
- {fileID: 11400000, guid: 9e558dc250163db40a4e1f7241ee15c2, type: 2}
- {fileID: 11400000, guid: 47d9da417e68970419335f80f4395239, type: 2}
- {fileID: 11400000, guid: 4badb7afa3370ba4d8a229584c5c744f, type: 2}

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/States/MidSliding.asset.meta


fileFormatVersion: 2
guid: ecc888784b4f5fd4db9430a844819e2b
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

81
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/AerialMovementActionSO.cs


using UnityEngine;
using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
/// <summary>
/// This Action handles horizontal movement while in the air, keeping momentum, simulating air resistance, and accelerating towards the desired speed.
/// </summary>
[CreateAssetMenu(fileName = "AerialMovement", menuName = "State Machines/Actions/Aerial Movement")]
public class AerialMovementActionSO : StateActionSO
{
public float Speed => _speed;
public float Acceleration => _acceleration;
[Tooltip("Desired horizontal movement speed while in the air")]
[SerializeField] [Range(0.1f, 100f)] private float _speed = 10f;
[Tooltip("The acceleration applied to reach the desired speed")]
[SerializeField] [Range(0.1f, 100f)] private float _acceleration = 20f;
protected override StateAction CreateAction() => new AerialMovementAction();
}
public class AerialMovementAction : StateAction
{
private new AerialMovementActionSO OriginSO => (AerialMovementActionSO)base.OriginSO;
private Protagonist _protagonist;
public override void Awake(StateMachine stateMachine)
{
_protagonist = stateMachine.GetComponent<Protagonist>();
}
public override void OnUpdate()
{
Vector3 velocity = _protagonist.movementVector;
Vector3 input = _protagonist.movementInput;
float speed = OriginSO.Speed;
float acceleration = OriginSO.Acceleration;
SetVelocityPerAxis(ref velocity.x, input.x, acceleration, speed);
SetVelocityPerAxis(ref velocity.z, input.z, acceleration, speed);
_protagonist.movementVector = velocity;
}
private void SetVelocityPerAxis(ref float currentAxisSpeed, float axisInput, float acceleration, float targetSpeed)
{
if (axisInput == 0f)
{
if (currentAxisSpeed != 0f)
{
ApplyAirResistance(ref currentAxisSpeed);
}
}
else
{
(float absVel, float absInput) = (Mathf.Abs(currentAxisSpeed), Mathf.Abs(axisInput));
(float signVel, float signInput) = (Mathf.Sign(currentAxisSpeed), Mathf.Sign(axisInput));
targetSpeed *= absInput;
if (signVel != signInput || absVel < targetSpeed)
{
currentAxisSpeed += axisInput * acceleration * Time.deltaTime;
currentAxisSpeed = Mathf.Clamp(currentAxisSpeed, -targetSpeed, targetSpeed);
}
else
{
ApplyAirResistance(ref currentAxisSpeed);
}
}
}
private void ApplyAirResistance(ref float value)
{
float sign = Mathf.Sign(value);
value -= sign * Protagonist.AIR_RESISTANCE * Time.deltaTime;
if (Mathf.Sign(value) != sign)
value = 0;
}
}

11
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/AerialMovementActionSO.cs.meta


fileFormatVersion: 2
guid: 0b9ee5024e536a5418bbc4f7484673d7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

44
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/StopMovementActionSO.cs


using UnityEngine;
using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
/// <summary>
/// An Action to clear a <see cref="Protagonist.movementVector"/> at the <see cref="StateAction.SpecificMoment"/> <see cref="StopMovementActionSO.Moment"/>
/// </summary>
[CreateAssetMenu(fileName = "StopMovementAction", menuName = "State Machines/Actions/Stop Movement")]
public class StopMovementActionSO : StateActionSO
{
[SerializeField] private StateAction.SpecificMoment _moment = default;
public StateAction.SpecificMoment Moment => _moment;
protected override StateAction CreateAction() => new StopMovement();
}
public class StopMovement : StateAction
{
private Protagonist _protagonist;
private new StopMovementActionSO OriginSO => (StopMovementActionSO)base.OriginSO;
public override void Awake(StateMachine stateMachine)
{
_protagonist = stateMachine.GetComponent<Protagonist>();
}
public override void OnUpdate()
{
if (OriginSO.Moment == SpecificMoment.OnUpdate)
_protagonist.movementVector = Vector3.zero;
}
public override void OnStateEnter()
{
if (OriginSO.Moment == SpecificMoment.OnStateEnter)
_protagonist.movementVector = Vector3.zero;
}
public override void OnStateExit()
{
if (OriginSO.Moment == SpecificMoment.OnStateExit)
_protagonist.movementVector = Vector3.zero;
}
}

11
UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/StopMovementActionSO.cs.meta


fileFormatVersion: 2
guid: ba8fe96b9505e1946a0637c5ff7a3904
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/MoveInTheAir.asset.meta


fileFormatVersion: 2
guid: f1f9b67c2b957d74dae6555b3598ae49
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

15
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/GravitySliding.asset


%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: 5e724f945a0fb204fa0f39919afe653b, type: 3}
m_Name: GravitySliding
m_EditorClassIdentifier:
verticalPull: -10

8
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/GravitySliding.asset.meta


fileFormatVersion: 2
guid: 088f3e34793299349983d53aaf39e5e3
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:

15
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Actions/MoveInTheAir.asset


%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: 09fcb347b6cb3524c9f59fbde36ec7c7, type: 3}
m_Name: MoveInTheAir
m_EditorClassIdentifier:
speed: 5
正在加载...
取消
保存