Last active
December 29, 2019 19:36
-
-
Save contrasting/a99d46501135dfcd3f9557108e0fae47 to your computer and use it in GitHub Desktop.
Fun little experiment to rewrite the algorithm for going uphill with recursion rather than iteration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void GoUphill(VectorP potentialPos, VectorP response, int y, float potentialDist) | |
| { | |
| // found non colliding height | |
| if (response == VectorP.zero) | |
| { | |
| // move to this position | |
| UpdatePosition(potentialPos); | |
| return; | |
| } | |
| // not found? stay where you are mate | |
| if (y > potentialDist * _verticalMovementTolerance) | |
| { | |
| return; | |
| } | |
| VectorP newVelocity = velocity; | |
| // search upwards | |
| potentialPos.y += 1; | |
| newVelocity.y = y / Time.deltaTime; | |
| // need new velocity to fix clipping terrain | |
| response = GetCollisionResponse(potentialPos, newVelocity.angle); | |
| GoUphill(potentialPos, response, y + 1, potentialDist); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment