Holloweye Posted February 6, 2010 Share Posted February 6, 2010 Well I want a object to move first fast and then slower when it comes closer to its destination. I dont want to use like: Destination/10 and loop that all the time beacause first its ugly and second I would need a if statement because it would take forever to come to the end. So I was think about useing Cos(x)+1. But I can't figure out how I should do it. I guess the integral would be the total movement so the destination. Hum easyer to show with a image: How would I do this? Help, Thanks Quote Link to comment Share on other sites More sharing options...
Canardia Posted February 6, 2010 Share Posted February 6, 2010 I think you should use a Bezier curve, then you don't have to wait so long until /x is limes target. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Rick Posted February 6, 2010 Share Posted February 6, 2010 Could you interpolate? You could have a variable amount of points between the current location and the destination. Each cycle check the distance between the current location and goal, then based on that distance you get a number of points to interpolate between. Then move to the first point in one cycle. The next cycle comes around and do it all over again. Because of the variable amount of points the larger the distance the less points you do in the interpolate which will give you a bigger jump to the goal. The closer you get though you increase the number of points you interpolate which gives you smaller jumps to the distance. Then put a cap on the number of jumps so you eventually will get to your goal. This is how I plan on doing network movement smoothing when the final destination between a clients players is different than the server says they should be. This will smooth out the fix between where a player is on my screen vs where the server says they should be. It avoids the instant snapping of the position. Quote Link to comment Share on other sites More sharing options...
Holloweye Posted February 6, 2010 Author Share Posted February 6, 2010 Could you interpolate? You could have a variable amount of points between the current location and the destination. Each cycle check the distance between the current location and goal, then based on that distance you get a number of points to interpolate between. Then move to the first point in one cycle. The next cycle comes around and do it all over again. Because of the variable amount of points the larger the distance the less points you do in the interpolate which will give you a bigger jump to the goal. The closer you get though you increase the number of points you interpolate which gives you smaller jumps to the distance. Then put a cap on the number of jumps so you eventually will get to your goal. This is how I plan on doing network movement smoothing when the final destination between a clients players is different than the server says they should be. This will smooth out the fix between where a player is on my screen vs where the server says they should be. It avoids the instant snapping of the position. Hum... Could you show in some kind of simple code example? Quote Link to comment Share on other sites More sharing options...
Rick Posted February 6, 2010 Share Posted February 6, 2010 still working on itI haven't put this into practice yet but here is the idea. It sounds like you know your goal location. If you do then you have a starting point and a destination point to move something along. Here would be a linear movement from point A to point B where it starts out fast but gets slower as you get to your destination point. double interpolated(double a, double b, double u) { return a + u * (b - a); } int p1x = 0; // current location int p1y = 0; int p2x = 5; // destination location int p2y = 10; int steps = 5; // the higher this number the smaller the movement will be int px, py; // the point I should move to on this cycle px = interpolated(p1x, p2x, (double) 1 / steps); py = interpolated(p1y, p2y, (double) 1 / steps); So for the steps parameter, you can make some sort of calculation on what it should be based on the EntityDistance() between your current location and the destination location. The smaller the number EntityDistance() returns the larger the steps get, which would mean the shorter the first step if between the current location and the goal. You'd have to put some cap on how small steps could get so you eventually reach our goal. I'm not a big math guy so there might be another way to get all the points where they get closer together as you reach your target all at once, but this might give more flexibility if the goal target can move. Quote Link to comment Share on other sites More sharing options...
Holloweye Posted February 6, 2010 Author Share Posted February 6, 2010 Wow very nice. Thanks! I will try it Quote Link to comment Share on other sites More sharing options...
Josh Posted February 6, 2010 Share Posted February 6, 2010 ...because it would take forever to come to the end. Use Curve(), and have a lower threshold for the minimum distance the step can be. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.