add stair and ground movement profile
This commit is contained in:
parent
e9d7d39f2b
commit
2a23d4cf9c
@ -5,18 +5,34 @@ using UnityEngine;
|
|||||||
|
|
||||||
namespace __Prototype.Scripts
|
namespace __Prototype.Scripts
|
||||||
{
|
{
|
||||||
public class TestGroundMorion : GroundProfileMotion
|
public class TestGroundMorion : GroundProfileMotionBehaviour
|
||||||
{
|
{
|
||||||
[GroupConfigurations, SerializeField] private Vector3 localDirection = Vector3.right;
|
[GroupConfigurations, SerializeField] private Vector3 localDirection = Vector3.right;
|
||||||
[GroupConfigurations, SerializeField] private float speed = 2f;
|
[GroupConfigurations, SerializeField] private float speed = 2f;
|
||||||
[GroupConfigurations, SerializeField] private float maxDistance = 4f;
|
[GroupConfigurations, SerializeField] private float maxDistance = 4f;
|
||||||
[GroupConfigurations, SerializeField] private bool pingPong = true;
|
[GroupConfigurations, SerializeField] private bool pingPong = true;
|
||||||
[GroupConfigurations, SerializeField] private bool moveOnStart;
|
[GroupConfigurations, SerializeField] private bool moveOnStart;
|
||||||
|
|
||||||
public override Vector3 Velocity { get; protected set; }
|
public Vector3 Velocity
|
||||||
public override Vector3 DeltaPosition { get; protected set; }
|
{
|
||||||
public override bool IsMoving { get; protected set; }
|
get => GroundProfileMotion.Velocity;
|
||||||
public override bool IsStatic { get; protected set; } = false;
|
private set => GroundProfileMotion.Velocity = value;
|
||||||
|
}
|
||||||
|
public Vector3 DeltaPosition
|
||||||
|
{
|
||||||
|
get => GroundProfileMotion.DeltaPosition;
|
||||||
|
private set => GroundProfileMotion.DeltaPosition = value;
|
||||||
|
}
|
||||||
|
public bool IsMoving
|
||||||
|
{
|
||||||
|
get => GroundProfileMotion.IsMoving;
|
||||||
|
private set => GroundProfileMotion.IsMoving = value;
|
||||||
|
}
|
||||||
|
public bool IsStatic
|
||||||
|
{
|
||||||
|
get => GroundProfileMotion.IsStatic;
|
||||||
|
private set => GroundProfileMotion.IsStatic = value;
|
||||||
|
}
|
||||||
|
|
||||||
private Vector3 _startPosition;
|
private Vector3 _startPosition;
|
||||||
private Vector3 _lastPosition;
|
private Vector3 _lastPosition;
|
||||||
@ -69,7 +85,7 @@ namespace __Prototype.Scripts
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
next = _startPosition + worldDirection * Mathf.Sign(distanceFromStart) * maxDistance;
|
next = _startPosition + worldDirection * (Mathf.Sign(distanceFromStart) * maxDistance);
|
||||||
Stop();
|
Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,14 @@ PrefabInstance:
|
|||||||
serializedVersion: 3
|
serializedVersion: 3
|
||||||
m_TransformParent: {fileID: 0}
|
m_TransformParent: {fileID: 0}
|
||||||
m_Modifications:
|
m_Modifications:
|
||||||
|
- target: {fileID: 101776470001583037, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
||||||
|
propertyPath: movementProfiles.Array.size
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 101776470001583037, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
||||||
|
propertyPath: 'movementProfiles.Array.data[0]'
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 5801231790879681971}
|
||||||
- target: {fileID: 221717111884494654, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
- target: {fileID: 221717111884494654, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
||||||
propertyPath: m_Mesh
|
propertyPath: m_Mesh
|
||||||
value:
|
value:
|
||||||
@ -99,6 +107,9 @@ PrefabInstance:
|
|||||||
- targetCorrespondingSourceObject: {fileID: 6524376507900539265, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
- targetCorrespondingSourceObject: {fileID: 6524376507900539265, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
||||||
insertIndex: -1
|
insertIndex: -1
|
||||||
addedObject: {fileID: 116909126457648545}
|
addedObject: {fileID: 116909126457648545}
|
||||||
|
- targetCorrespondingSourceObject: {fileID: 6524376507900539265, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
||||||
|
insertIndex: -1
|
||||||
|
addedObject: {fileID: 5801231790879681971}
|
||||||
m_SourcePrefab: {fileID: 100100000, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
m_SourcePrefab: {fileID: 100100000, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
||||||
--- !u!114 &2719093777726527478 stripped
|
--- !u!114 &2719093777726527478 stripped
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@ -134,3 +145,23 @@ MonoBehaviour:
|
|||||||
sizeZ: 1
|
sizeZ: 1
|
||||||
x: 1
|
x: 1
|
||||||
z: 1
|
z: 1
|
||||||
|
--- !u!114 &5801231790879681971
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 9140983697215042600}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: bdd4ad30e2d149b58a2f84fa9a5b5fbc, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier: Assembly-CSharp::Intrepid.Core.Grounding.GroundProfileMovementBehaviour
|
||||||
|
id: 9d7dfeaecb7e4204ba7dd29dede5075d
|
||||||
|
groundProfileMovement:
|
||||||
|
speedMultiplier: 1
|
||||||
|
accelerationMultiplier: 1
|
||||||
|
decelerationMultiplier: 1
|
||||||
|
uphillSpeedMultiplier: 0.75
|
||||||
|
downhillSpeedMultiplier: 1
|
||||||
|
sidewaysSpeedMultiplier: 0.9
|
||||||
|
|||||||
@ -8,6 +8,14 @@ PrefabInstance:
|
|||||||
serializedVersion: 3
|
serializedVersion: 3
|
||||||
m_TransformParent: {fileID: 0}
|
m_TransformParent: {fileID: 0}
|
||||||
m_Modifications:
|
m_Modifications:
|
||||||
|
- target: {fileID: 101776470001583037, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
||||||
|
propertyPath: movementProfiles.Array.size
|
||||||
|
value: 1
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 101776470001583037, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
||||||
|
propertyPath: 'movementProfiles.Array.data[0]'
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 1964621128587179894}
|
||||||
- target: {fileID: 221717111884494654, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
- target: {fileID: 221717111884494654, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
||||||
propertyPath: m_Mesh
|
propertyPath: m_Mesh
|
||||||
value:
|
value:
|
||||||
@ -103,6 +111,9 @@ PrefabInstance:
|
|||||||
- targetCorrespondingSourceObject: {fileID: 6524376507900539265, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
- targetCorrespondingSourceObject: {fileID: 6524376507900539265, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
||||||
insertIndex: -1
|
insertIndex: -1
|
||||||
addedObject: {fileID: 2575929596551944822}
|
addedObject: {fileID: 2575929596551944822}
|
||||||
|
- targetCorrespondingSourceObject: {fileID: 6524376507900539265, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
||||||
|
insertIndex: -1
|
||||||
|
addedObject: {fileID: 1964621128587179894}
|
||||||
m_SourcePrefab: {fileID: 100100000, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
m_SourcePrefab: {fileID: 100100000, guid: 84ef2ec4df393420d973aa876a8778b6, type: 3}
|
||||||
--- !u!114 &3525235759526726985 stripped
|
--- !u!114 &3525235759526726985 stripped
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@ -138,3 +149,23 @@ MonoBehaviour:
|
|||||||
sizeZ: 1
|
sizeZ: 1
|
||||||
x: 1
|
x: 1
|
||||||
z: 1
|
z: 1
|
||||||
|
--- !u!114 &1964621128587179894
|
||||||
|
MonoBehaviour:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_CorrespondingSourceObject: {fileID: 0}
|
||||||
|
m_PrefabInstance: {fileID: 0}
|
||||||
|
m_PrefabAsset: {fileID: 0}
|
||||||
|
m_GameObject: {fileID: 7749360569717010071}
|
||||||
|
m_Enabled: 1
|
||||||
|
m_EditorHideFlags: 0
|
||||||
|
m_Script: {fileID: 11500000, guid: bdd4ad30e2d149b58a2f84fa9a5b5fbc, type: 3}
|
||||||
|
m_Name:
|
||||||
|
m_EditorClassIdentifier: Assembly-CSharp::Intrepid.Core.Grounding.GroundProfileMovementBehaviour
|
||||||
|
id: afbca706aa91413387e401bb77925f70
|
||||||
|
groundProfileMovement:
|
||||||
|
speedMultiplier: 1
|
||||||
|
accelerationMultiplier: 1
|
||||||
|
decelerationMultiplier: 1
|
||||||
|
uphillSpeedMultiplier: 0.5
|
||||||
|
downhillSpeedMultiplier: 1
|
||||||
|
sidewaysSpeedMultiplier: 0.9
|
||||||
|
|||||||
63
Assets/Prefabs/Prototypes/Ground_Stair_Left_Prototype.prefab
Normal file
63
Assets/Prefabs/Prototypes/Ground_Stair_Left_Prototype.prefab
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1001 &3382806052188099058
|
||||||
|
PrefabInstance:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Modification:
|
||||||
|
serializedVersion: 3
|
||||||
|
m_TransformParent: {fileID: 0}
|
||||||
|
m_Modifications:
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.y
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.w
|
||||||
|
value: 0.7071068
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.y
|
||||||
|
value: -0.7071068
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.y
|
||||||
|
value: -90
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3608453355090094120, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_Mesh
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7749360569717010071, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_Name
|
||||||
|
value: Ground_Stair_Left_Prototype
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
m_RemovedComponents: []
|
||||||
|
m_RemovedGameObjects: []
|
||||||
|
m_AddedGameObjects: []
|
||||||
|
m_AddedComponents: []
|
||||||
|
m_SourcePrefab: {fileID: 100100000, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c11973af2c21642658a917c1253a53f4
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -0,0 +1,63 @@
|
|||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!1001 &8988140421347768202
|
||||||
|
PrefabInstance:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
serializedVersion: 2
|
||||||
|
m_Modification:
|
||||||
|
serializedVersion: 3
|
||||||
|
m_TransformParent: {fileID: 0}
|
||||||
|
m_Modifications:
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.y
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalPosition.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.w
|
||||||
|
value: 0.7071068
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.y
|
||||||
|
value: 0.7071068
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalRotation.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.x
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.y
|
||||||
|
value: 90
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3190054200416215303, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_LocalEulerAnglesHint.z
|
||||||
|
value: 0
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 3608453355090094120, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_Mesh
|
||||||
|
value:
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
- target: {fileID: 7749360569717010071, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
|
propertyPath: m_Name
|
||||||
|
value: Ground_Stair_Right_Prototype
|
||||||
|
objectReference: {fileID: 0}
|
||||||
|
m_RemovedComponents: []
|
||||||
|
m_RemovedGameObjects: []
|
||||||
|
m_AddedGameObjects: []
|
||||||
|
m_AddedComponents: []
|
||||||
|
m_SourcePrefab: {fileID: 100100000, guid: da66eef8ff1ce4c3eaf46c09ad26e70b, type: 3}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3e0d56cfe99b4417a8f7c924adc9581e
|
||||||
|
PrefabImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
File diff suppressed because one or more lines are too long
@ -370,7 +370,7 @@ namespace Intrepid.Core.Entities
|
|||||||
RegisterStableGroundNormal(normal);
|
RegisterStableGroundNormal(normal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector3 ResolveMovementVelocity(Vector3 velocity)
|
private Vector3 ResolveMovementVelocity(Vector3 velocity)
|
||||||
{
|
{
|
||||||
if (velocity.sqrMagnitude <= GonConstants.CommonZeroSqrt)
|
if (velocity.sqrMagnitude <= GonConstants.CommonZeroSqrt)
|
||||||
@ -383,10 +383,67 @@ namespace Intrepid.Core.Entities
|
|||||||
return velocity;
|
return velocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ProjectVelocityOnPlane(
|
var projectedVelocity = ProjectVelocityOnPlane(
|
||||||
velocity,
|
velocity,
|
||||||
StableGroundNormal
|
StableGroundNormal
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return ApplyGroundMovementProfile(
|
||||||
|
projectedVelocity,
|
||||||
|
StableGroundNormal
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vector3 ApplyGroundMovementProfile(
|
||||||
|
Vector3 velocity,
|
||||||
|
Vector3 groundNormal)
|
||||||
|
{
|
||||||
|
if (!IsGrounded || !CurrentGroundProfiles.TryGetGroundProfileMovement(out var movement))
|
||||||
|
{
|
||||||
|
return velocity;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (velocity.sqrMagnitude <= GonConstants.CommonZeroSqrt)
|
||||||
|
{
|
||||||
|
return Vector3.zero;
|
||||||
|
}
|
||||||
|
|
||||||
|
var downhill = Vector3.ProjectOnPlane(
|
||||||
|
Vector3.down,
|
||||||
|
groundNormal.normalized
|
||||||
|
);
|
||||||
|
|
||||||
|
if (downhill.sqrMagnitude <= GonConstants.CommonZeroSqrt)
|
||||||
|
{
|
||||||
|
return velocity * movement.SpeedMultiplier;
|
||||||
|
}
|
||||||
|
|
||||||
|
downhill.Normalize();
|
||||||
|
|
||||||
|
var moveDirection = velocity.normalized;
|
||||||
|
|
||||||
|
var downhillFactor = Vector3.Dot(moveDirection, downhill);
|
||||||
|
|
||||||
|
float directionalMultiplier;
|
||||||
|
|
||||||
|
if (downhillFactor > 0f)
|
||||||
|
{
|
||||||
|
directionalMultiplier = Mathf.Lerp(
|
||||||
|
movement.SidewaysSpeedMultiplier,
|
||||||
|
movement.DownhillSpeedMultiplier,
|
||||||
|
downhillFactor
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
directionalMultiplier = Mathf.Lerp(
|
||||||
|
movement.SidewaysSpeedMultiplier,
|
||||||
|
movement.UphillSpeedMultiplier,
|
||||||
|
-downhillFactor
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return velocity * (movement.SpeedMultiplier * directionalMultiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RegisterStableGroundNormal(Vector3 normal)
|
private void RegisterStableGroundNormal(Vector3 normal)
|
||||||
|
|||||||
@ -2,7 +2,7 @@ using Intrepid.Utilities;
|
|||||||
|
|
||||||
namespace Intrepid.Core.Grounding
|
namespace Intrepid.Core.Grounding
|
||||||
{
|
{
|
||||||
public abstract class GroundProfile : Identification
|
public abstract class GroundProfileBehaviour : Identification
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,12 +0,0 @@
|
|||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace Intrepid.Core.Grounding
|
|
||||||
{
|
|
||||||
public abstract class GroundProfileMotion : GroundProfile
|
|
||||||
{
|
|
||||||
public abstract Vector3 Velocity { get; protected set; }
|
|
||||||
public abstract Vector3 DeltaPosition { get; protected set; }
|
|
||||||
public abstract bool IsMoving { get; protected set; }
|
|
||||||
public abstract bool IsStatic { get; protected set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Intrepid.Core.Grounding
|
||||||
|
{
|
||||||
|
public class GroundProfileMotionBehaviour : GroundProfileBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private GroundProfileMotion groundProfileMotion;
|
||||||
|
|
||||||
|
public GroundProfileMotion GroundProfileMotion => groundProfileMotion;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Intrepid.Core.Grounding
|
||||||
|
{
|
||||||
|
public class GroundProfileMovementBehaviour : GroundProfileBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private GroundProfileMovement groundProfileMovement = GroundProfileMovement.NoModifiers;
|
||||||
|
|
||||||
|
public GroundProfileMovement GroundProfileMovement => groundProfileMovement;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: bdd4ad30e2d149b58a2f84fa9a5b5fbc
|
||||||
|
timeCreated: 1781681309
|
||||||
@ -1,19 +1,129 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Intrepid.Utilities;
|
||||||
|
using Sirenix.OdinInspector;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Intrepid.Core.Grounding
|
namespace Intrepid.Core.Grounding
|
||||||
{
|
{
|
||||||
|
[Serializable]
|
||||||
|
public abstract class GroundProfile
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable, GroupConfigurations("Motion Profile"), HideLabel]
|
||||||
|
public sealed class GroundProfileMotion : GroundProfile
|
||||||
|
{
|
||||||
|
[SerializeField] private Vector3 velocity;
|
||||||
|
[SerializeField] private Vector3 deltaPosition;
|
||||||
|
[SerializeField] private bool isMoving;
|
||||||
|
[SerializeField] private bool isStatic;
|
||||||
|
|
||||||
|
public Vector3 Velocity
|
||||||
|
{
|
||||||
|
get => velocity;
|
||||||
|
set => velocity = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3 DeltaPosition
|
||||||
|
{
|
||||||
|
get => deltaPosition;
|
||||||
|
set => deltaPosition = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsMoving
|
||||||
|
{
|
||||||
|
get => isMoving;
|
||||||
|
set => isMoving = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsStatic
|
||||||
|
{
|
||||||
|
get => isStatic;
|
||||||
|
set => isStatic = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable, GroupConfigurations("Movement Profile"), HideLabel]
|
||||||
|
public class GroundProfileMovement : GroundProfile
|
||||||
|
{
|
||||||
|
[SerializeField] private float speedMultiplier;
|
||||||
|
[SerializeField] private float accelerationMultiplier;
|
||||||
|
[SerializeField] private float decelerationMultiplier;
|
||||||
|
[SerializeField] private float uphillSpeedMultiplier;
|
||||||
|
[SerializeField] private float downhillSpeedMultiplier;
|
||||||
|
[SerializeField] private float sidewaysSpeedMultiplier;
|
||||||
|
|
||||||
|
public float SpeedMultiplier
|
||||||
|
{
|
||||||
|
get => speedMultiplier;
|
||||||
|
protected set => speedMultiplier = value;
|
||||||
|
}
|
||||||
|
public float AccelerationMultiplier
|
||||||
|
{
|
||||||
|
get => accelerationMultiplier;
|
||||||
|
protected set => accelerationMultiplier = value;
|
||||||
|
}
|
||||||
|
public float DecelerationMultiplier
|
||||||
|
{
|
||||||
|
get => decelerationMultiplier;
|
||||||
|
protected set => decelerationMultiplier = value;
|
||||||
|
}
|
||||||
|
public float UphillSpeedMultiplier
|
||||||
|
{
|
||||||
|
get => uphillSpeedMultiplier;
|
||||||
|
protected set => uphillSpeedMultiplier = value;
|
||||||
|
}
|
||||||
|
public float DownhillSpeedMultiplier
|
||||||
|
{
|
||||||
|
get => downhillSpeedMultiplier;
|
||||||
|
protected set => downhillSpeedMultiplier = value;
|
||||||
|
}
|
||||||
|
public float SidewaysSpeedMultiplier
|
||||||
|
{
|
||||||
|
get => sidewaysSpeedMultiplier;
|
||||||
|
protected set => sidewaysSpeedMultiplier = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GroundProfileMovement NoModifiers => new()
|
||||||
|
{
|
||||||
|
SpeedMultiplier = 1f,
|
||||||
|
AccelerationMultiplier = 1f,
|
||||||
|
DecelerationMultiplier = 1f,
|
||||||
|
UphillSpeedMultiplier = 1f,
|
||||||
|
DownhillSpeedMultiplier = 1f,
|
||||||
|
SidewaysSpeedMultiplier = 1f,
|
||||||
|
};
|
||||||
|
|
||||||
|
public static GroundProfileMovement operator *(GroundProfileMovement a, GroundProfileMovement b)
|
||||||
|
{
|
||||||
|
return new GroundProfileMovement
|
||||||
|
{
|
||||||
|
SpeedMultiplier = a.SpeedMultiplier * b.SpeedMultiplier,
|
||||||
|
AccelerationMultiplier = a.AccelerationMultiplier * b.AccelerationMultiplier,
|
||||||
|
DecelerationMultiplier = a.DecelerationMultiplier * b.DecelerationMultiplier,
|
||||||
|
UphillSpeedMultiplier = a.UphillSpeedMultiplier * b.UphillSpeedMultiplier,
|
||||||
|
DownhillSpeedMultiplier = a.DownhillSpeedMultiplier * b.DownhillSpeedMultiplier,
|
||||||
|
SidewaysSpeedMultiplier = a.SidewaysSpeedMultiplier * b.SidewaysSpeedMultiplier,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public readonly struct GroundProfiles
|
public readonly struct GroundProfiles
|
||||||
{
|
{
|
||||||
public static readonly GroundProfiles None = new(false);
|
public static readonly GroundProfiles None = new(false);
|
||||||
|
|
||||||
private readonly bool _isSafe;
|
private readonly bool _isSafe;
|
||||||
private GroundProfileMotion GroundProfileMotion { get; }
|
private GroundProfileMotion GroundProfileMotion { get; }
|
||||||
|
private GroundProfileMovement GroundProfileMovement { get; }
|
||||||
public bool IsSafe => CheckIfThisProfileIsSafe();
|
public bool IsSafe => CheckIfThisProfileIsSafe();
|
||||||
|
|
||||||
public GroundProfiles(bool isSafe, GroundProfileMotion groundProfileMotion = null)
|
public GroundProfiles(bool isSafe,
|
||||||
|
GroundProfileMotion groundProfileMotion = null,
|
||||||
|
GroundProfileMovement groundProfileMovement = null)
|
||||||
{
|
{
|
||||||
_isSafe = isSafe;
|
_isSafe = isSafe;
|
||||||
GroundProfileMotion = groundProfileMotion;
|
GroundProfileMotion = groundProfileMotion;
|
||||||
|
GroundProfileMovement = groundProfileMovement;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CheckIfThisProfileIsSafe()
|
private bool CheckIfThisProfileIsSafe()
|
||||||
@ -28,7 +138,7 @@ namespace Intrepid.Core.Grounding
|
|||||||
|
|
||||||
private bool TryGet<T>(T value, out T profile) where T: GroundProfile
|
private bool TryGet<T>(T value, out T profile) where T: GroundProfile
|
||||||
{
|
{
|
||||||
if (value.IsNull())
|
if (value is null)
|
||||||
{
|
{
|
||||||
profile = null;
|
profile = null;
|
||||||
return false;
|
return false;
|
||||||
@ -42,5 +152,10 @@ namespace Intrepid.Core.Grounding
|
|||||||
{
|
{
|
||||||
return TryGet(GroundProfileMotion, out profile);
|
return TryGet(GroundProfileMotion, out profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool TryGetGroundProfileMovement(out GroundProfileMovement profile)
|
||||||
|
{
|
||||||
|
return TryGet(GroundProfileMovement, out profile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Intrepid.Utilities;
|
using Intrepid.Utilities;
|
||||||
using Sirenix.OdinInspector;
|
using Sirenix.OdinInspector;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -13,8 +15,8 @@ namespace Intrepid.Core.Grounding
|
|||||||
{
|
{
|
||||||
[GroupInjections, SerializeField] private BoxCollider boxCollider;
|
[GroupInjections, SerializeField] private BoxCollider boxCollider;
|
||||||
[GroupConfigurations("Profiles"), SerializeField] private bool safe = true;
|
[GroupConfigurations("Profiles"), SerializeField] private bool safe = true;
|
||||||
[GroupConfigurations("Profiles"), SerializeField] private GroundProfileMotion groundProfileMotion;
|
[GroupConfigurations("Profiles"), SerializeField] private GroundProfileMotionBehaviour motionProfile;
|
||||||
|
[GroupConfigurations("Profiles"), SerializeField] private List<GroundProfileMovementBehaviour> movementProfiles = new();
|
||||||
|
|
||||||
[GroupDebug, ShowInInspector, ReadOnly] public Vector3 Position { get; private set; }
|
[GroupDebug, ShowInInspector, ReadOnly] public Vector3 Position { get; private set; }
|
||||||
[GroupDebug, ShowInInspector, ReadOnly] public Vector3 Normal { get; private set; }
|
[GroupDebug, ShowInInspector, ReadOnly] public Vector3 Normal { get; private set; }
|
||||||
@ -38,7 +40,12 @@ namespace Intrepid.Core.Grounding
|
|||||||
[GroupDebug, Button(ButtonSizes.Medium)]
|
[GroupDebug, Button(ButtonSizes.Medium)]
|
||||||
private void RefreshProfiles()
|
private void RefreshProfiles()
|
||||||
{
|
{
|
||||||
GroundProfiles = new GroundProfiles(safe, groundProfileMotion);
|
var groundProfileMovement = movementProfiles.Count == 0
|
||||||
|
? null
|
||||||
|
: movementProfiles
|
||||||
|
.Select(behaviour => behaviour.GroundProfileMovement)
|
||||||
|
.Aggregate(GroundProfileMovement.NoModifiers, (a, b) => a * b);
|
||||||
|
GroundProfiles = new GroundProfiles(safe, motionProfile?.GroundProfileMotion, groundProfileMovement);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Button(ButtonSizes.Medium)]
|
[Button(ButtonSizes.Medium)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user