I'm trying to handle slopes in a tiles based world. I'm using basic linear interpolation to find the Y coordinate of the character based on his X position. But i have a problem, when the character move up or down the slopes the sprite is all jittery, it doesn't move smoothly and i can't figure out why.
I don't use a "true physics engine" all the engine does is AABB collision and tell when a collision occurs and let you handle the reaction. When the character is on a slope no "gravity" (Y velocity) is applied the Y position is adjusted by hand using the linear interpolation result.
Here is the linear interpolation function that i use :
float InterpolateY(Vector2 point1, Vector2 point2, float x)
{
float x1 = point1.X;
float y1 = point1.Y;
float x2 = point2.X;
float y2 = point2.Y;
float y = y1 + (x - x1) * (y2 - y1) / (x2 - x1);
return y;
}
I've made a webm to show you the problem (ignore the fact that the sprite sink into other tile it doesn't matter for the moment)
Link to the webm : https://webmshare.com/play/vPXLD
InterpolateY
is rounded to nearest integer, is that correct? Can you show of more of theInterpolateY
s context (input, handling output etc)? \$\endgroup\$ – wondra Apr 27 '18 at 11:00