gpt4 book ai didi

java - 使用 libgdx 触摸板旋转播放器以面向移动方向

转载 作者:行者123 更新时间:2023-12-01 09:54:51 24 4
gpt4 key购买 nike

我已经遇到这个问题超过 2 天了。不断地调整。我就是无法完成它。

我有一个玩家纹理(玩家面向左侧),我想使用触摸板旋转它。所以玩家将面向他的奔跑方向。

到目前为止我有这个:

double facerotation = Math.atan2(touchpad.getKnobPercentY(), touchpad.getKnobPercentX());

spriteBatch.draw(runningFrame, player.getPosition().x, player.getPosition().y, Player.getSize() / 2, Player.getSize() / 2, Player.getSize(), Player.getSize(), 1, 1, facerotation * 100, false);

但是使用“roation*100”时,他会旋转大约 2 圈,而没有“roation*100”时,他几乎不会旋转。我什至尝试切换上面的 atan2 函数的 X 和 Y 值。但我从来没有让他只沿着我移动的方向旋转。我还尝试了 atan 函数,也交换了 X 和 Y 值。

请帮助我。我尝试了数千种方法、不同的计算以及我在谷歌上看到的东西。没有给我带来想要的效果。

最佳答案

只需使用 Vector2。用它来存储旋钮百分比 y 和 x。然后你可以用vector2.angle()得到以度为单位的旋转。

Vector2 v = new Vector2(touchpad.getKnobPercentX(), touchpad.getKnobPercentY());
float angle = v.angle();
runningFrame.setRotation(angle);

关于java - 使用 libgdx 触摸板旋转播放器以面向移动方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37333086/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com