Update SurfController.cs

This commit is contained in:
Olezen
2020-01-01 13:35:07 +01:00
committed by GitHub
parent a38a6ad099
commit 4f37024fa5

View File

@@ -85,22 +85,30 @@ namespace Fragsurf.Movement {
speed = _surfer.moveData.velocity.magnitude; speed = _surfer.moveData.velocity.magnitude;
_surfer.moveData.velocity.y = yVel; _surfer.moveData.velocity.y = yVel;
float maxDistPerFrame = 0.05f; if (_surfer.moveData.velocity.sqrMagnitude == 0f) {
Vector3 velocityThisFrame = _surfer.moveData.velocity * _deltaTime;
float velocityDist = velocityThisFrame.magnitude;
float velocityDistLeft = velocityDist;
float initialVel = velocityDistLeft;
while (velocityDistLeft > 0f) {
float amountThisLoop = Mathf.Min (maxDistPerFrame, velocityDistLeft); // Do collisions while standing still
velocityDistLeft -= amountThisLoop; SurfPhysics.ResolveCollisions (_surfer.collider, ref _surfer.moveData.origin, ref _surfer.moveData.velocity, _surfer.moveData.rigidbodyPushForce, 1f, _surfer.moveData.stepOffset, _surfer);
// increment origin } else {
Vector3 velThisLoop = velocityThisFrame * (amountThisLoop / initialVel);
_surfer.moveData.origin += velThisLoop;
// don't penetrate walls float maxDistPerFrame = 0.2f;
SurfPhysics.ResolveCollisions (_surfer.collider, ref _surfer.moveData.origin, ref _surfer.moveData.velocity, _surfer.moveData.rigidbodyPushForce, amountThisLoop / velocityDist, _surfer.moveData.useStepOffset ? _surfer.moveData.stepOffset : 0f, _surfer); Vector3 velocityThisFrame = _surfer.moveData.velocity * _deltaTime;
float velocityDistLeft = velocityThisFrame.magnitude;
float initialVel = velocityDistLeft;
while (velocityDistLeft > 0f) {
float amountThisLoop = Mathf.Min (maxDistPerFrame, velocityDistLeft);
velocityDistLeft -= amountThisLoop;
// increment origin
Vector3 velThisLoop = velocityThisFrame * (amountThisLoop / initialVel);
_surfer.moveData.origin += velThisLoop;
// don't penetrate walls
SurfPhysics.ResolveCollisions (_surfer.collider, ref _surfer.moveData.origin, ref _surfer.moveData.velocity, _surfer.moveData.rigidbodyPushForce, amountThisLoop / initialVel, _surfer.moveData.stepOffset, _surfer);
}
} }