Fix ledge-stuck bug

This commit is contained in:
Jens Pitkänen 2020-08-10 19:42:06 +03:00
parent 6598abf504
commit 5964d9432e
2 changed files with 7 additions and 6 deletions

View File

@ -1738,7 +1738,7 @@ MonoBehaviour:
GroundCastLength: 0.2 GroundCastLength: 0.2
GroundLayer: GroundLayer:
serializedVersion: 2 serializedVersion: 2
m_Bits: 10497 m_Bits: 256
ShowGroundCast: 0 ShowGroundCast: 0
ShowMoveVector: 0 ShowMoveVector: 0
--- !u!1 &7391558913556166741 --- !u!1 &7391558913556166741

View File

@ -293,9 +293,11 @@ namespace NeonTea.Quakeball.Players {
GravitationalVelocity += Physics.gravity * Time.deltaTime; GravitationalVelocity += Physics.gravity * Time.deltaTime;
} }
Vector3 GroundNormal = GroundCast();
float FrictionVelocityFactor = Mathf.Max(GroundVelocity.magnitude, MoveStyle.StopVelocity); float FrictionVelocityFactor = Mathf.Max(GroundVelocity.magnitude, MoveStyle.StopVelocity);
float Deccel = FrictionVelocityFactor * Time.deltaTime; float Deccel = FrictionVelocityFactor * Time.deltaTime;
if (Grounded) { if (Grounded || GroundNormal != Vector3.up) {
Deccel *= MoveStyle.Friction; Deccel *= MoveStyle.Friction;
} else { } else {
Deccel *= MoveStyle.AirFriction; Deccel *= MoveStyle.AirFriction;
@ -303,11 +305,10 @@ namespace NeonTea.Quakeball.Players {
float FrictionedVelocity = Mathf.Max(0, GroundVelocity.magnitude - Deccel); float FrictionedVelocity = Mathf.Max(0, GroundVelocity.magnitude - Deccel);
GroundVelocity = GroundVelocity.normalized * FrictionedVelocity; GroundVelocity = GroundVelocity.normalized * FrictionedVelocity;
Vector3 GroundNormal = GroundCast();
Vector3 FixedHeading = Vector3.ProjectOnPlane(MoveDirection, GroundNormal).normalized; Vector3 FixedHeading = Vector3.ProjectOnPlane(MoveDirection, GroundNormal).normalized;
float CurrentSpeed = Vector3.Dot(GroundVelocity, FixedHeading); float CurrentSpeed = Vector3.Dot(GroundVelocity, FixedHeading);
float Acceleration = MoveStyle.TargetVelocity * Time.deltaTime; float Acceleration = MoveStyle.TargetVelocity * Time.deltaTime;
if (Grounded) { if (Grounded || GroundNormal != Vector3.up) {
Acceleration *= MoveStyle.Acceleration; Acceleration *= MoveStyle.Acceleration;
} else { } else {
Acceleration *= MoveStyle.AirAcceleration; Acceleration *= MoveStyle.AirAcceleration;
@ -315,8 +316,7 @@ namespace NeonTea.Quakeball.Players {
Acceleration = Mathf.Min(Acceleration, MoveStyle.TargetVelocity - CurrentSpeed); Acceleration = Mathf.Min(Acceleration, MoveStyle.TargetVelocity - CurrentSpeed);
GroundVelocity += FixedHeading * Acceleration; GroundVelocity += FixedHeading * Acceleration;
CharacterController.Move(GroundVelocity * Time.deltaTime); CharacterController.Move((GravitationalVelocity + GroundVelocity) * Time.deltaTime);
CollisionFlags flags = CharacterController.Move(GravitationalVelocity * Time.deltaTime);
if (CharacterController.isGrounded) { if (CharacterController.isGrounded) {
GroundedTime = Time.time; GroundedTime = Time.time;
LatestGroundedY = transform.position.y; LatestGroundedY = transform.position.y;
@ -325,6 +325,7 @@ namespace NeonTea.Quakeball.Players {
// Hit a roof while jumping, reset falling velocity downwards (same as "static gravity" when grounded) // Hit a roof while jumping, reset falling velocity downwards (same as "static gravity" when grounded)
GravitationalVelocity.y = GroundCastLength; GravitationalVelocity.y = GroundCastLength;
} }
if (ShowMoveVector) { if (ShowMoveVector) {
Debug.DrawLine(transform.position + CharacterController.center, transform.position + CharacterController.center + GravitationalVelocity, Color.yellow, 1.0f); Debug.DrawLine(transform.position + CharacterController.center, transform.position + CharacterController.center + GravitationalVelocity, Color.yellow, 1.0f);
Debug.DrawLine(transform.position + CharacterController.center, transform.position + CharacterController.center + GroundVelocity, Color.green, 1.0f); Debug.DrawLine(transform.position + CharacterController.center, transform.position + CharacterController.center + GroundVelocity, Color.green, 1.0f);