【发布时间】:2019-05-15 14:55:56
【问题描述】:
我正在 Unity 中制作逼真的管道阀轮旋转。这是我已经拥有的:
[SerializeField] private float cur_HP;
private const float max_HP = 100;
private Vector3 PrevmousePos;
private bool SpaceIsPressed;
// Start is called before the first frame update
void Start()
{
cur_HP = max_HP;
}
// Update is called once per frame
void Update()
{
SpaceIsPressed = Input.GetKey(KeyCode.Space);
Wheel();
}
void Wheel()
{
Vector3 mouseDelta = Input.mousePosition - PrevmousePos;
if (mouseDelta.x > 0 && SpaceIsPressed)
{
float amount = 0.01f;
cur_HP -= mouseDelta.x * amount;
} else if(mouseDelta.x < 0 && SpaceIsPressed)
{
float amount = 0.01f;
cur_HP += mouseDelta.x * amount;
}
if (cur_HP <= 0)
{
cur_HP = 0;
Debug.Log("You have unlocked");
}
if (cur_HP > 100)
{
cur_HP = 100;
}
transform.localRotation = Quaternion.Euler(0, 0, (720 / max_HP * cur_HP));
PrevmousePos = Input.mousePosition;
}
我现在想要什么。就像现实生活中的阀门管轮一样。如果你想松开它。你需要用很大的力才能向右旋转。然后越松开它就越容易旋转。如果你想收紧它,反之亦然。所以在我的帮助下,我的小脑袋想不出任何数学或代码。你们能给我一些提示或提示怎么做吗?
编辑:这是我现在拥有的 gif,我正在使用鼠标右扫的空格键来旋转滚轮https://gyazo.com/004b2f8c4424476c796ae42ad28dacce
【问题讨论】:
-
所以,基本上,它应该越向右旋转越少?最大 720 度?
-
向右旋转应该旋转得越少。就像你知道的真正的管阀轮一样。如果你曾经用螺丝刀拧过螺丝?你越紧它就会变得越来越难。就像那样@FredrikSchön
-
线性?或者就在最后,就像螺丝刀一样?
-
我认为是线性的。因为拧得越紧,旋转就越困难。反之亦然。顺便说一句,720 度是最大值