Fix ledge-stuck bug
This commit is contained in:
parent
6598abf504
commit
5964d9432e
@ -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
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user