【发布时间】:2017-01-14 15:05:52
【问题描述】:
在我的项目中,当我与桥发生碰撞时,我有一座桥,它旋转并且不停止旋转,我想要的是通过特定点旋转该桥并停止旋转,该桥位于游戏对象内这是我的枢轴点,一般我旋转枢轴点而不是桥,所以我这样做了:
using UnityEngine;
using System.Collections;
public class fallBridge : MonoBehaviour {
private Rigidbody ball;
public GameObject bridgePivot;
private bool colided;
private bool rotating = true;
// Update is called once per frame
void Start(){
colided = false;
}
void Update () {
if (colided) {
if (rotating) {
Vector3 to = new Vector3 (0, 0, -85);
if (Vector3.Distance (bridgePivot.transform.eulerAngles, to) > 0.01f) {
bridgePivot.transform.eulerAngles = Vector3.Lerp (bridgePivot.transform.rotation.eulerAngles, to, Time.deltaTime);
} else {
bridgePivot.transform.eulerAngles = to;
rotating = false;
}
}
}
}
void OnCollisionEnter(Collision other)
{
ball = GameObject.FindWithTag ("Player").GetComponent<Rigidbody> ();
if (other.gameObject.tag == "Player" && ball.transform.localScale == new Vector3(2.0f,2.0f,2.0f)) {
Debug.Log("ENTER");
colided = true;
}
}
}
我做错了什么??碰撞检测工作完美,但在更新方法上它永远不会停止旋转:S
【问题讨论】:
-
debug.log 看看为什么不满足条件
if (Vector3.Distance (bridgePivot.transform.eulerAngles, to) > 0.01f)
标签: c# unity3d rotation unity5