Hi!
Consider you have a world composed of cells. Your character has to move between one cell to another, just with vertical and horizontal movements, not diagonal ones, and that you can’t stay in the middle of a cell - so every time you start a movement, you should arrive to that cell.
To accomplish this I thought about Vector2.Lerp
, doing like this:
_movementLerpAmount = MathHelper.Clamp(
_movementLerpAmount + Speed * (float)elapsed.TotalSeconds,
0f,
1f);
CharacterPosition = Vector2.Lerp(_startingLocation, _nextLocation, _movementLerpAmount);
Where _startingLocation
is the starting cell, and _nextLocation
is the cell in which I want to go.
It is working perfectly, but when I want to keep going in a direction (instead of stopping in a cell), I see a little movement “click” or “stop” everytime the character reaches a cell. I debugged and I saw the that _movementLerpAmount
is constant until I reach a cell, but at a certain point it isn’t. I think that is the problem:
0 // Starting from a cell
0.3
0.6
0.9
1 // Arrived
0
0.3
…
Do you have any suggestions?
Thanks!