# Lag reduction using Cubic Spline (alias Bezier)

This topic is 4583 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I'm making a multiplayer game and for now i'm moving around objects in 2D (x,y). If I put directly the received position, its very choppy. Thats why I searched for an algorithm to make it smooth between the last 2 key frames. I read this article about Cubic Spline : http://www.gamedev.net/reference/articles/article914.asp But some part is not well explained and the result is incorrect. The entity just spring around. If I put everything like the article. Then I realized that the velocities need to be rescale depending of the duration of the animation. But resized to what, I tried everything :( Here how I did it :
void interpolate(long & cFProgression, CoordFrame & from, CoordFrame & to, float delay)
{
cFProgression++; // We increment
long size = to.frameID - from.frameID;
if (cFProgression > size)
{
// We are moving it normaly
position += vel * delay;
}
else if (cFPrograssion >= 0)
{
// We get the time delta (from 0 to 1)
float t = (float)cFProgression / (float)size;
float animTime = (float)size / 30.0f;

// We interpolate using the cubicSpline (bezier) function
position = cubicSpline(
from.position,  // Initial pos
from.position + from.vel * animTime, // Anchor Point 1
to.position - to.vel * animTime,  // Anchor point 2
to.position,  // Final Pos
t); // DeltaTime
}
}


This loop springy less using the "* animTime". But I cant fine the correct value to put here. I also tried his mixed "cubic spline, and quadratic motion" :

CVector3f acc = to.vel - from.vel;

CVector3f coord1 = from.position;
CVector3f coord2 = from.position + from.vel;
CVector3f coord3 = to.position + to.vel * animTime + acc * .5f * (animTime * animTime);
CVector3f coord4 = coord3 - (to.vel + acc * animTime);
position = cubicSpline(coord1, coord2, coord3, coord4, t);


But this gives very wierd results :P I tried to change values, remove the "* animTime". I tried a lot of thing, my entity always spring, a little or a lot. I also found this post about the article : http://www.gamedev.net/community/forums/topic.asp?topic_id=386485 But its not very usefull. Thanks for any help/suggestions !!!

##### Share on other sites
Ok found it !!!!!!!
By myself.

this line :
float animTime = (float)size / 30.0f;

should be :
float animTime = (float)size / (30.0f * 3.0f);

The 30.0f is my number of update frame per second (like quake)
The 3.0f, its because its a cubic equation.
First I tried 2.0f, but it was springy.
I finnaly remember that the perfect fraction for a bezier equation is 1/3.

:):)

Hope this thread will help people that try the above article and realize that its not working well.

Thanks to me! lol

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 16
• 14
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634094
• Total Posts
3015497
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!