AndEngine smooth turning

379 views Asked by At

I'm developing a simple educational game using AndEngine. To move the object on the path I use Path and I am struggling to give it a smooth turning effect.

Can anyone explain me how to make object move along specified path with smooth turns?

1

There are 1 answers

0
Scalarr On BEST ANSWER

Path is not really set up for that if I remember correctly. However, imagine you have a sprite named wasp, then use amplitude and frequency to adjust the motion of a sinusodial:

final float amp = 10.0; //amplitude of the motion
final float xfreq = 2.25; //frequency of x
final float xfreq = 0.25; //frequency of y
final float cx = amp * (float)Math.sin(this.mEngine.getSecondsElapsedTotal() / xfreq);
final float cy = amp * (float)Math.sin(this.mEngine.getSecondsElapsedTotal() / yfreq);
wasp.setPosition(cx, cy);

This is a periodic motion, but depending on involved functions and randomness it can be made to become very complex. Key is to make a function that varies over time e.g this.mEngine.getSecondsElapsedTotal().