【发布时间】:2014-11-14 01:32:52
【问题描述】:
我正在努力让角色四处推动物体。问题是,一旦他接触到一个物体,他就会开始移动它,即使是偶然的接触并且角色没有面对物体的方向。
我想要做的是在碰撞发生时获取对象的方向,如果相机真的朝向那个方向,允许玩家移动它。
目前我只能获得物体的方向,但我不知道如何将其与相机的方向进行比较。
这就是我现在正在尝试的:
void OnCollisionEnter(Collision col) {
float maxOffset = 1f;
if (col.gameObject.name == "Sol") {
// Calculate object direction
Vector3 direction = (col.transform.position - transform.position).normalized;
// Check the offset with the camera rotation (this doesn't work)
Vector3 offset = direccion - Camera.main.transform.rotation.eulerAngles.normalized;
if(offset.x + offset.y + offset.z < maxOffset) {
// Move the object
}
}
【问题讨论】:
标签: unity3d