浏览代码

New day, new test

/main
Ciro Continisio 4 年前
当前提交
c3118a36
共有 5 个文件被更改,包括 50 次插入59 次删除
  1. 9
      UOP1_Project/Assets/Prefabs/Characters/PigChef.prefab
  2. 18
      UOP1_Project/Assets/Scenes/WIP/TestingGround_Small.unity
  3. 48
      UOP1_Project/Assets/Scripts/Characters/Protagonist.cs
  4. 6
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Actions/SlideActionSO.cs
  5. 28
      UOP1_Project/Assets/Scripts/Characters/StateMachine/Conditions/IsSlidingConditionSO.cs

9
UOP1_Project/Assets/Prefabs/Characters/PigChef.prefab


m_Enabled: 1
serializedVersion: 2
m_Height: 1.3
m_Radius: 0.25
m_SlopeLimit: 45
m_StepOffset: 0.25
m_Radius: 0.3
m_SlopeLimit: 50
m_StepOffset: 0.15
m_SkinWidth: 0.02
m_MinMoveDistance: 0.005
m_Center: {x: 0, y: 0.65, z: 0}

ray1: {fileID: 5986570136067168862}
ray2: {fileID: 6950735986475152375}
ray3: {fileID: 6171081068863781697}
canMoveForward: 0
--- !u!114 &6243045328629046901
MonoBehaviour:
m_ObjectHideFlags: 0

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 3716520544714381952}
m_LocalRotation: {x: -0, y: -1, z: -0, w: 0}
m_LocalPosition: {x: 0.004, y: 0.2954, z: 0.278}
m_LocalPosition: {x: 0, y: 0.15, z: 0.3}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1083073290189785667}

18
UOP1_Project/Assets/Scenes/WIP/TestingGround_Small.unity


- target: {fileID: 463132372906762298, guid: 45632f0a227c860489bcba0eb1f4ec3e,
type: 3}
propertyPath: m_FollowOffset.y
value: 4.093733
value: 3.447653
value: -8.60862
value: -8.062856
value: 4.093733
value: 3.447653
value: -8.60862
value: -8.062856
objectReference: {fileID: 0}
- target: {fileID: 1657732992883833910, guid: 45632f0a227c860489bcba0eb1f4ec3e,
type: 3}

- target: {fileID: 2678045054851453813, guid: 45632f0a227c860489bcba0eb1f4ec3e,
type: 3}
propertyPath: m_FollowOffset.y
value: 4.093733
value: 3.447653
value: -8.60862
value: -8.062856
objectReference: {fileID: 0}
- target: {fileID: 2808035858438402709, guid: 45632f0a227c860489bcba0eb1f4ec3e,
type: 3}

- target: {fileID: 2808035858438402709, guid: 45632f0a227c860489bcba0eb1f4ec3e,
type: 3}
propertyPath: m_LocalRotation.x
value: 0.102249905
value: 0.10224989
value: -0.08917595
value: -0.08917597
value: 0.024490178
value: 0.024490183
objectReference: {fileID: 0}
- target: {fileID: 2955398947125553842, guid: 45632f0a227c860489bcba0eb1f4ec3e,
type: 3}

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


[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 Vector3 rayGroundNormal = Vector3.up;
[NonSerialized] public ControllerColliderHit lastHit;
[NonSerialized] public Vector3 stepNormal = Vector3.up;
[NonSerialized] public Vector3 spherecastGroundNormal = Vector3.up;
[NonSerialized] public bool isRunning; // Used when using the keyboard to run, brings the normalised speed to 1

public const float AIR_RESISTANCE = 5f;
public Transform ray1, ray2, ray3; //Temporary references
public bool canMoveForward;
//private void OnControllerColliderHit(ControllerColliderHit hit)
//{
// lastHit = hit;
//}
private void OnControllerColliderHit(ControllerColliderHit hit)
{
lastHit = hit;
}
//Adds listeners for events being triggered in the InputReader script
private void OnEnable()

private void GroundCheck()
{
rayGroundNormal = Vector3.zero;
if(Physics.Raycast(ray1.position, Vector3.down, out RaycastHit hitResults, 1f))
{
rayGroundNormal += hitResults.normal;
}
if (Physics.Raycast(ray2.position, Vector3.down, out hitResults, 1f))
{
rayGroundNormal += hitResults.normal;
}
if (Physics.Raycast(ray3.position, Vector3.down, out hitResults, 1f))
{
rayGroundNormal += hitResults.normal;
}
rayGroundNormal.Normalize();
//Ray sphereRay = new Ray(transform.position + Vector3.up * .3f, Vector3.down);
//if (Physics.SphereCast(sphereRay, .3f, out hitResults, 1f))
//{
// spherecastGroundNormal = hitResults.normal;
// if(!rayFoundGround)
// {
// rayGroundNormal = spherecastGroundNormal;
// }
//}
//else
//{
// spherecastGroundNormal = Vector3.up;
//}
Vector3 origin = transform.position + Vector3.up * 1.5f;
Debug.DrawLine(origin, origin + rayGroundNormal, Color.red);
//Debug.DrawLine(origin, origin + spherecastGroundNormal, Color.green);
canMoveForward = !Physics.Raycast(ray1.position, transform.forward, out RaycastHit hitResults, .2f);
}
private void RecalculateMovement()

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


public override void OnUpdate()
{
float speed = -Physics.gravity.y * Protagonist.GRAVITY_MULTIPLIER * .3f;
Vector3 slideDirection = new Vector3(_protagonist.rayGroundNormal.x, -_protagonist.rayGroundNormal.y, _protagonist.rayGroundNormal.z);
Vector3.OrthoNormalize(ref _protagonist.rayGroundNormal, ref slideDirection);
Vector3 hitNormal = _protagonist.lastHit.normal;
Vector3 slideDirection = new Vector3(hitNormal.x, -hitNormal.y, hitNormal.z);
Vector3.OrthoNormalize(ref hitNormal, ref slideDirection);
//Vector3 slidingMovement = _protagonist.movementVector;
//// Cheap way to avoid overshooting the character, which causes it to move away from the slope

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


protected override bool Statement()
{
float slope = Vector3.Angle(Vector3.up, _protagonistScript.rayGroundNormal);
Debug.Log(slope);
return slope >= _characterController.slopeLimit;
Vector3 lastHitProj = _protagonistScript.lastHit.point;
lastHitProj.y = 0f;
if (_protagonistScript.canMoveForward)
{
float isForward = Vector3.Dot(_protagonistScript.transform.forward, lastHitProj.normalized);
if (isForward >= .9f)
{
return false;
}
else
{
float slope = Vector3.Angle(Vector3.up, _protagonistScript.lastHit.normal);
return slope >= _characterController.slopeLimit;
}
}
else
{
float slope = Vector3.Angle(Vector3.up, _protagonistScript.lastHit.normal);
return slope >= _characterController.slopeLimit;
}
}
}
正在加载...
取消
保存