Unity头Y轴旋转夹

时间:2017-03-26 05:54:26

标签: c# unity3d

我正在努力制作一个统一的FPP模式,你可以看到你真实的身体。我创造了一个模型,操纵一切。我的头会旋转到相机,但我不希望玩家能够围绕他的身体旋转。我已经在x轴上夹紧了旋转,但是在绕y轴夹紧时会出现问题。

<% @prayers.each do |p| %>
  <%= p.date %> <%= p.time %>
  <%= simple_form_for p do |f| %>
    <%= f.input :name %>
  <% end %>
<% end %>

我认为在0和360度角度时旋转有限制。我的代码完美无缺,直到身体达到360度。虽然我的相机会抖动,然后从隐形墙“反弹”回到它来自的一侧。

1 个答案:

答案 0 :(得分:0)

确定。我已经明白了。如果某人有类似的问题,这里是代码,也许它也适用于他们。

void Update () {

    yaw += Input.GetAxis ("Mouse Y") * mouseHorizontalSensitivity;


    yaw =  Mathf.Clamp (yaw, -30f, 80f);  // It's pitch but my code works weird



    pitch -= Input.GetAxis ("Mouse X") * mouseVerticalSensitivity;
    pitch = Mathf.Clamp (pitch, -90f, 90f);  // it's yaw


    currentRotation = Vector3.SmoothDamp (currentRotation, new Vector3 (-pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
    transform.localEulerAngles = currentRotation;

// my mouse input wouldn't go down which caused the model to rotate indeffinitely so i added smoothing to 0 for rotating around Y axis which here is labeled as pitch
    if (!Input.GetKey (KeyCode.LeftAlt))
        pitch = Mathf.SmoothDamp(pitch, 0f, ref rotationSmoothVelocity2, rotationSmoothTime); 

}

相关问题