Skip to content

Instantly share code, notes, and snippets.

@contrasting
Last active December 29, 2019 19:36
Show Gist options
  • Select an option

  • Save contrasting/a99d46501135dfcd3f9557108e0fae47 to your computer and use it in GitHub Desktop.

Select an option

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
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