Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving between co-ordinates, Java Algorithms

Ok this question is going to be a little abstract.

I have an icon moving along a line which is represented by a series of coordinates stored in a vector, and I am iterating through them. The distance between coordinates is variable. So sometimes the icon will move slowly and smoothly, and others it will jump several 100 pixels at a time.

I am having trouble coming up with an algorithm to split up each set of coordinates it must travel between into a set of relative coordinates where the number is based on size, so that transition is smooth no matter how many co-ords are on a single line.

Any ideas would be much appreciated. Thanks :)

like image 822
John Avatar asked Dec 21 '25 04:12

John


2 Answers

Take a look at this discussion of the Main Game Loop.

And here's a quote from that page:

At this step, updates to all the objects in the game world are calculated and performed. Usually, a time step value is passed to all of the update methods indicating how much time has passed since the last update ...

You need to know 3 things:

  • how much time has elapsed since you last updated the position of your object?
  • what is the rate of movement of your object?
  • what is the direction (usually represented as a Ray) your object is moving?

From these, you can calculate the current position of the object.

like image 96
Drew Wills Avatar answered Dec 22 '25 18:12

Drew Wills


If you want the object to move at a constant speed, I'd suggest a time-based model, where your object is actually moving at a speed (pixels/second). You can still get it to hit every point(ish) if you spline along a curve (such as a catmull-rom curve).

like image 27
bkritzer Avatar answered Dec 22 '25 19:12

bkritzer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!