0
\$\begingroup\$

I have 2d game where my camera follows the player. Simplified, it copies the player position as its own.

Now I have some other object in the game, that I want to camera to follow. This is easy enough by not setting the camera's position with the player's, but with the position of the other object.

The problem is that this camera movement is instant. I'd like to have a more smooth transition (e.g. panning over the level to the given object).

How can I achieve this?

\$\endgroup\$
3
\$\begingroup\$

You need to interpolate between the camera's position and the target position. It looks like libgdx has a Vector2.lerp() linear interpolation method that you can use, however if you want something that has a smoother ease in/out you'll need to use another method, which it seems you can do using Vector2.interpolate(). Call one of these methods every frame and your camera's position will move smoothly to the target position instead of snapping.

\$\endgroup\$
  • \$\begingroup\$ This makes it sound almost too easy. I'll give a whirl tonight. \$\endgroup\$ – Ariejan May 17 '14 at 15:11
  • \$\begingroup\$ Lerping works fine for what I want to achieve! Thanks! \$\endgroup\$ – Ariejan May 17 '14 at 19:04
0
\$\begingroup\$

Since you are using lib gdx, this sound like a perfect use of the wonderful Tween Engine!

http://www.aurelienribon.com/blog/projects/universal-tween-engine/

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.