【问题标题】:How to clamp z rotation of a gameobject using touch input in unity without creating a jitter on y rotation如何在不产生 y 旋转抖动的情况下统一使用触摸输入来钳制游戏对象的 z 旋转
【发布时间】:2020-11-16 10:24:57
【问题描述】:

我可以使用下面的代码来限制我的游戏对象的 z 旋转,但它总是会在我第一次触摸时改变 y 旋转。我只想旋转z轴。

private float zRotation;

public void RotateMove()
{
    zRotation -= Input.GetTouch(0).deltaPosition.y * rotateSpeed * invert * Time.deltaTime;
    
    // this limits the rotatioon
    zRotation = Mathf.Clamp(zRotation, -80, 80);
    //this rotates the game obj
    lamp2Rotate.transform.eulerAngles = new Vector3(0.0f, 0.0f, zRotation);
}

【问题讨论】:

    标签: c# unity3d touch-event screen-rotation clamp


    【解决方案1】:

    听起来0 不是你想要的Y

    您可以改为保留其他两个旋转:

    var eulerAngles = lamp2Rotate.transform.eulerAngles;
    eulerAngles.z = zRotation;
    lamp2Rotate.transform.eulerAngles = eulerAngles;
    

    【讨论】:

    • 有没有办法防止它在 touchphase.moved 之前的第一次触摸时在 z 轴上旋转。它会立即移动我触摸屏幕,但我希望它在 touchphase.moved 之后这样做
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多