如何制作流畅的摄像机跟踪算法? [英] How to make a smooth camera follow algorithm?

查看:160
本文介绍了如何制作流畅的摄像机跟踪算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用LibGDX(Java)制作游戏。

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 always a bit late: character goes quick right, camera follows with slight delay, or if you suddenly appeared somewhere far, camera doesn't teleport instantly but travels at a top speed to you when it comes closer it slows down a bit and finds you again.

是否有任何libgdx libs可以做到这一点或任何人有这种经历?

Is there any libgdx libs that do that or anyone had this experience?

推荐答案

尝试一些简单的方法,例如距离的十分之一。它的效果非常好。

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;

这篇关于如何制作流畅的摄像机跟踪算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆