Search code examples
androidandenginerotateanimation

AndEngine smooth turning


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?


Solution

  • 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().