java - how to make a smooth camera follow algorithm_ [libgdx] - stack overflow.pdf
DESCRIPTION
java - How to make a smooth camera follow algorithm_ [LibGDX] - Stack Overflow.pdfTRANSCRIPT
![Page 1: java - How to make a smooth camera follow algorithm_ [LibGDX] - Stack Overflow.pdf](https://reader035.vdocument.in/reader035/viewer/2022081816/55cf99fe550346d033a00857/html5/thumbnails/1.jpg)
1/7/14 java - How to make a smooth camera follow algorithm? [LibGDX] - Stack Overflow
stackoverflow.com/questions/13227994/how-to-make-a-smooth-camera-follow-algorithm-libgdx 1/2
Take the 2-minute tour ×
Jens Piegsa1,719 1 5 23
Avetis Zakharyan87 8
2 Answers
Rod Hyde4,610 1 9 14
I am making a game with LibGDX (Java).
I need the camera to follow a fast moving character. The easiest way to do it is to just write this:
this.getCamera().position.set(obj.x, obj.y, 0);
But, is there any algorithm to make this more smooth? Like when camera is not that strict, and is alwaysa bit late: character goes quick right, camera follows with slight delay, or if you suddenly appearedsomewhere far, camera doesn't teleport instantly but travels at a top speed to you when it comes closerit slows down a bit and finds you again.
Is there any libgdx libs that do that or anyone had this experience?
java opengl 2d libgdx smoothscrolling
edited 11 hours ago asked Nov 5 '12 at 7:50
"But, is there any algorithm to make this more smooth?" Have you tried any algorithms on your own, or doneany Google searches for smooth camera interpolation or something? – Nicol Bolas Nov 5 '12 at 8:14
I tried it on my own and have several working examples, but I do not like result much, I was curiousif there canbe something already figured out as it sounds like something any game dev will need, Regarding googlesearch, I am not sure what to search, it brings tons of other stuff. – Avetis Zakharyan Nov 5 '12 at 13:48
Try something simple like lerping a tenth of the distance. It works surprisingly well.
float lerp = 0.1f;Vector3 position = this.getCamera().position;position.x += (Obj.x - position.x) * lerp;position.y += (Obj.y - position.y) * lerp;
answered Nov 13 '12 at 10:55
1 Suggestion: also multiply with deltatime to make the movement independent of the framerate. – Mortennobel Dec 18 '13 at 1:46
Take a look at Aurelion Ribon's Java Universal Tween Engine. This performs interpolation and hasseveral easing equations that I think would get you what you are looking for. It also has other advancedfeatures like waypointing and chaining certain actions together for other interesting effects.
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, noregistration required.
How to make a smooth camera follow algorithm? [LibGDX]
sign up
log in
tour
help
careers 2.0
add comment
add comment
![Page 2: java - How to make a smooth camera follow algorithm_ [LibGDX] - Stack Overflow.pdf](https://reader035.vdocument.in/reader035/viewer/2022081816/55cf99fe550346d033a00857/html5/thumbnails/2.jpg)
1/7/14 java - How to make a smooth camera follow algorithm? [LibGDX] - Stack Overflow
stackoverflow.com/questions/13227994/how-to-make-a-smooth-camera-follow-algorithm-libgdx 2/2
MutantXenu188 2 10
Your game logic could check to see if the character is moving quickly or has a step change in terms ofposition. In response to this, turn your current camera position over to the tween engine and let it takeover smoothly zooming to the character's current position.
answered Nov 5 '12 at 14:25
There's a forked project up on Github that does camera smoothing: github.com/tescott/smoothcam. Take alook at that or the project it was originally forked from. – MutantXenu May 30 '13 at 14:06
Not the answer you're looking for? Browse other questions tagged java opengl 2d
libgdx smooth‐scrolling or ask your own question.
add comment