我的游戏中有两个门.最初它们是关闭的.之后,它们将打开,并会在特定点停止(图片作为示例附上).到目前为止,我已经编写了一个脚本,该脚本可以连续旋转门.我想阻止他们,例如以45度角,需要种种建议.
using UnityEngine;
using System.Collections;
public class rotate : MonoBehaviour
{
public string rotate_along = "y";
public float speed = 10.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
if (rotate_along == "y") {
this.transform.Rotate (0, speed, 0);
} else if (rotate_along == "x") {
this.transform.Rotate (speed * Time.deltaTime, 0, 0);
} else if (rotate_along == "z") {
this.transform.Rotate (0, 0, speed * Time.deltaTime);
} else {
print ( "please! check your cordinate for rotating for "+gameObject.name );
}
}
}
解决方法:
我建议您为此使用Lerp或Slerp:
void Update() {
transform.rotation = Quaternion.Lerp(from.rotation, to.rotation, Time.time * speed);
}
这将使您的门自然顺畅地移动,就像在现实世界中一样,并使您避免在向量空间中编码恐怖. Unity社区提供了很多有关四元数如何工作的示例.在这里,您可以找到区别的简要说明:
http://answers.unity3d.com/questions/389713/detaliled-explanation-about-given-vector3slerp-exa.html
原文地址:https://codeday.me/bug/20191026/1935379.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。