默认用法,不支持旋转:
var cross = Vector3.Cross(lhsObject.transform.position, rhsObject.transform.position); if (cross.y > 0) //side if(cross.y < 0)//another side
用forward,从而支持旋转:
void OnCollisionEnter(Collision other) { Vector3 direction = other.contacts[0].point - transform.position; var cross = Vector3.Cross(transform.forward, direction); if (cross.y < 0) print ("Left"); else print("right"); } function OnCollisionEnter(other:Collision){ var direction:Vector3 = other.contacts[0].point - transform.position; var cross :Vector3 = Vector3.Cross(transform.forward, direction); if (cross.y < 0) print ("Left"); else print("right"); }
论坛上还看见一个demo,加深对差集的理解:(得到一个forward方向,取得up,right,left)
// original vector: var forward: Vector3 = Vector3(0.5, 0.7, 0.8); // up direction: var up: Vector3 = Vector3(0.0, 1.0, 0.0); // find right vector: var right = Vector3.Cross(forward.normalized, up.normalized); var left = -right;
时间: 2024-09-28 18:32:35