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
GroundLayer:
serializedVersion: 2
m_Bits: 10497
m_Bits: 256
ShowGroundCast: 0
ShowMoveVector: 0
--- !u!1 &7391558913556166741

View File

@ -293,9 +293,11 @@ namespace NeonTea.Quakeball.Players {
GravitationalVelocity += Physics.gravity * Time.deltaTime;
}
Vector3 GroundNormal = GroundCast();
float FrictionVelocityFactor = Mathf.Max(GroundVelocity.magnitude, MoveStyle.StopVelocity);
float Deccel = FrictionVelocityFactor * Time.deltaTime;
if (Grounded) {
if (Grounded || GroundNormal != Vector3.up) {
Deccel *= MoveStyle.Friction;
} else {
Deccel *= MoveStyle.AirFriction;
@ -303,11 +305,10 @@ namespace NeonTea.Quakeball.Players {
float FrictionedVelocity = Mathf.Max(0, GroundVelocity.magnitude - Deccel);
GroundVelocity = GroundVelocity.normalized * FrictionedVelocity;
Vector3 GroundNormal = GroundCast();
Vector3 FixedHeading = Vector3.ProjectOnPlane(MoveDirection, GroundNormal).normalized;
float CurrentSpeed = Vector3.Dot(GroundVelocity, FixedHeading);
float Acceleration = MoveStyle.TargetVelocity * Time.deltaTime;
if (Grounded) {
if (Grounded || GroundNormal != Vector3.up) {
Acceleration *= MoveStyle.Acceleration;
} else {
Acceleration *= MoveStyle.AirAcceleration;
@ -315,8 +316,7 @@ namespace NeonTea.Quakeball.Players {
Acceleration = Mathf.Min(Acceleration, MoveStyle.TargetVelocity - CurrentSpeed);
GroundVelocity += FixedHeading * Acceleration;
CharacterController.Move(GroundVelocity * Time.deltaTime);
CollisionFlags flags = CharacterController.Move(GravitationalVelocity * Time.deltaTime);
CharacterController.Move((GravitationalVelocity + GroundVelocity) * Time.deltaTime);
if (CharacterController.isGrounded) {
GroundedTime = Time.time;
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)
GravitationalVelocity.y = GroundCastLength;
}
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 + GroundVelocity, Color.green, 1.0f);