How to make a smooth camera follow algorithm?

大城市里の小女人 提交于 2019-11-30 01:47:58
Rod Hyde

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 * deltaTime;
position.y += (Obj.y - position.y) * lerp * deltaTime;

Take a look at Aurelion Ribon's Java Universal Tween Engine. This performs interpolation and has several easing equations that I think would get you what you are looking for. It also has other advanced features like waypointing and chaining certain actions together for other interesting effects.

Your game logic could check to see if the character is moving quickly or has a step change in terms of position. In response to this, turn your current camera position over to the tween engine and let it take over -- smoothly zooming to the character's current position.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!