Jump to content

[Solved] Movement question


Holloweye
 Share

Recommended Posts

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:

post-83-12654808489627_thumb.png

 

 

How would I do this? Help, Thanks :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...