# Tile slopes and jittery movement

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

• Hey mate. I don't know the exact answer, but when I saw your question it reminded me of this tutorial I read a while back. They have a section on implementing slopes which you might find helpful. It doesn't show a lot of code but it does describe in some detail how to implement them correctly. higherorderfun.com/blog/2012/05/20/… – craftworkgames Apr 27 '18 at 6:52
• Judging from the example value of InterpolateY is rounded to nearest integer, is that correct? Can you show of more of the InterpolateYs context (input, handling output etc)? – wondra Apr 27 '18 at 11:00
• @wondra thats exact, i posted an answers to my own questions, thank you for your help :) – GahrbajKahn Apr 28 '18 at 12:34