Creating an arc between two points for interpolation in Java -
i've got top down game i'm making , want enemies able move across screen in arc. right move in straight line between 2 edges of screen. generate start position on 1 edge find random position somewhere across screen , calculate movement speeds multiplying sin/cos of angle speed variable.
i'd use these points generate arc between them , use move enemies along it. thought maybe sort of spline trick im not entirely sure how create one, nor more how use interpolate characters. think @ point more of math question programming hope can anyways. thanks.
yes, spline work you. recommend cubic spline, because later on if wanted different shape, maybe street fighter style uppercut, re-use same code. remember cubic spline being decent, general solution.
as far solving cubic spline recommend google pseudo code makes sense you. that's if want generically solve suitable cubic spline on fly.
in practice, imagine shape want same time? if so, can solve few general cases of spline , save fast data structure improve performance. in example, y=x
suitable array holding necessary information (pre-processed) x[0] = 1,x[1] = 1,x[2] = 2 ... x[n] = n
.
in practice, come equation model simple 2 point spline. cubic equation has 4 unknowns. have 2 data points @ least, you're starting point , end point. in addition, can calculate derivative of him when jumps. fourth point use either point want him jump through, or derivative when lands. use https://www.wolframalpha.com/ solve equation you. or use equation solve cubics.
another thing can calculate arc using quadratic equation + gravity + wind resistance. again, google knows how solve that. page found looks trick. http://www.physicsclassroom.com/class/vectors/lesson-2/non-horizontally-launched-projectiles-problem-solv
Comments
Post a Comment