本文介绍了如何使光滑的摄像头跟踪算法? [LibGDX]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个游戏LibGDX(爪哇)。

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库的做到这一点或任何人有过这种经历?

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

推荐答案

尝试一些简单的像lerping距离的十分之一。它的工作原理出奇地好。

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;

这篇关于如何使光滑的摄像头跟踪算法? [LibGDX]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 02:00