浏览代码

State Machine - Proposed fix for Issue 228 (#227)

* Added Sliding to JumpAscending

Player was unable to jump if sliding which caused the player to get stuck in geometry/holes.

* Added IsActuallyMoving Condition SO and update PigChef Transition Table

IsActuallyMovingSO evaluates character movement by the character controller's velosity.sqrMagnitude. Returns true if the character controller is moving beyond the threshold. Characters can no longer jump while sliding but can jump if they get stuck.

* Update .gitignore

* Small fixes

Reconnected disconnected assets in the TransitionTable, reverted changes on the .gitignore, added multiplication in threshold verification equation

Co-authored-by: Ciro Continisio <ciro@unity3d.com>
/main
GitHub 4 年前
当前提交
e9c2c909
共有 6 个文件被更改,包括 89 次插入1 次删除
  1. 21
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/PigChef_TransitionTable.asset
  2. 2
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsSlidingConditionSO.cs
  3. 16
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Conditions/IsActuallyMoving.asset
  4. 8
      UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Conditions/IsActuallyMoving.asset.meta
  5. 32
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsActuallyMovingConditionSO.cs
  6. 11
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsActuallyMovingConditionSO.cs.meta

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


- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 620f4efd93744084a8ac9ba272f093dc, type: 2}
Operator: 0
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: c5090b215e4f1594f9d1ef6680cd15bb, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 027d32476800b3543b2f5446a59054c8, type: 2}
ToState: {fileID: 11400000, guid: 4c2c0dc4f7ee62b4d95b20ac3dce281e, type: 2}
Conditions:

Conditions:
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: c5090b215e4f1594f9d1ef6680cd15bb, type: 2}
Operator: 0
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: ddd205b8cff23bc48b47aa5538d549be, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
ToState: {fileID: 11400000, guid: 0aa906b71b1b4504d950f5ee8e1f06e8, type: 2}

Operator: 0
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: c5090b215e4f1594f9d1ef6680cd15bb, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
ToState: {fileID: 11400000, guid: c57ed1dc57a890943b2648ca8a581075, type: 2}
Conditions:

Condition: {fileID: 11400000, guid: c5090b215e4f1594f9d1ef6680cd15bb, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 4c2c0dc4f7ee62b4d95b20ac3dce281e, type: 2}
ToState: {fileID: 11400000, guid: 0aa906b71b1b4504d950f5ee8e1f06e8, type: 2}
Conditions:
- ExpectedResult: 1
Condition: {fileID: 11400000, guid: ddd205b8cff23bc48b47aa5538d549be, type: 2}
Operator: 0
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: 620f4efd93744084a8ac9ba272f093dc, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: 4c2c0dc4f7ee62b4d95b20ac3dce281e, type: 2}
Operator: 0
- ExpectedResult: 0
Condition: {fileID: 11400000, guid: ddd205b8cff23bc48b47aa5538d549be, type: 2}
Operator: 0
- FromState: {fileID: 11400000, guid: e128814ff6dbf63449bbc4dc8b6dc066, type: 2}
ToState: {fileID: 11400000, guid: ff92a93d8a8694247b507d811c88e402, type: 2}

2
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsSlidingConditionSO.cs


{
if (_protagonistScript.lastHit == null)
return false;
float currentSlope = Vector3.Angle(Vector3.up, _protagonistScript.lastHit.normal);
return (currentSlope >= _characterController.slopeLimit);
}

16
UOP1_Project/Assets/ScriptableObjects/StateMachine/Protagonist/Conditions/IsActuallyMoving.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: ac06717fdbf1afa42a253d91cabf8bf9, type: 3}
m_Name: IsActuallyMoving
m_EditorClassIdentifier:
cacheResult: 1
_treshold: 0.02

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


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

32
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsActuallyMovingConditionSO.cs


using UnityEngine;
using UOP1.StateMachine;
using UOP1.StateMachine.ScriptableObjects;
[CreateAssetMenu(fileName = "IsActuallyMoving", menuName = "State Machines/Conditions/Is Actually Moving")]
public class IsActuallyMovingConditionSO : StateConditionSO
{
[SerializeField] private float _treshold = 0.02f;
protected override Condition CreateCondition() => new IsActuallyMovingCondition(_treshold);
}
public class IsActuallyMovingCondition : Condition
{
private float _treshold;
private CharacterController _characterController;
public override void Awake(StateMachine stateMachine)
{
_characterController = stateMachine.GetComponent<CharacterController>();
}
public IsActuallyMovingCondition(float treshold)
{
_treshold = treshold;
}
protected override bool Statement()
{
return _characterController.velocity.sqrMagnitude > _treshold * _treshold;
}
}

11
UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsActuallyMovingConditionSO.cs.meta


fileFormatVersion: 2
guid: ac06717fdbf1afa42a253d91cabf8bf9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存