码迷,mamicode.com
首页 > 其他好文 > 详细

U3D差集判断是否在左边或右边

时间:2015-04-30 00:49:39      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:

默认用法,不支持旋转:

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;

 

U3D差集判断是否在左边或右边

标签:

原文地址:http://www.cnblogs.com/hont/p/4467839.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!