Vector3.Dot 判断方位
判断方位
假设空间中有这几个坐标,判断一个物体在另一个物体的左边还是右边,前后还是后面
物体空间图
假如以C为中心,判断L是在它的左边还是右边
判断方法
using UnityEngine;
using System.Collections; public class GetDirection : MonoBehaviour
{
public Transform cubeF;
public Transform cubeB;
public Transform cubeL;
public Transform cubeR;
public Transform cubeC; void Update ()
{
Vector3 forward = transform.TransformDirection (Vector3.forward);
Vector3 toOther = cubeB.position - transform.position;
if (Vector3.Dot (forward, toOther) < 0) {
print ("The other transform is behind me !");
} else {
print ("The other transform is ahead me !");
} Vector3 left = transform.TransformDirection (Vector3.right);
Vector3 toOtherL = cubeL.position - transform.position;
if (Vector3.Dot (left, toOtherL) < 0) {
print ("The other transform is left me !");
} else {
print ("The other transform is right me !");
}
} }
改变位置测试
运行拖动物体在cubeC的不同位置
Vector3.Dot 判断方位的更多相关文章
- Vector3.Dot 与Vector3.Cross
Vector3.Dot(点积) : 点积的计算方式为: a·b=|a|·|b|cos<a,b>; 其中<a,b>和<b,a> 夹角不分顺序; 物理学中点积用来计算 ...
- Unity3D之Vector3.Dot和Vector3.Cross的使用
在unity3d中,Vector3.Dot表示求两个向量的点积;Vector3.Cross表示求两个向量的叉积. 点积计算的结果为数值,而叉积计算的结果为向量.两者要注意区别开来. 在几何数学中: 1 ...
- Unity3D之Vector3.Dot和Vector3.Cross采用
在Unity3D中.Vector3.Dot表示求两个向量的点积;Vector3.Cross表示求两个向量的叉积. 点积计算的结果为数值,而叉积计算的结果为向量.两者要注意差别开来. 在几何数学 ...
- Unity3D中目标相对自身的前后左右方位判断
http://blog.csdn.net/cen616899547/article/details/38336185 在做rpg类游戏的过程中,经常遇到要判断周围怪物相对自身的方位 1.判断目标在 ...
- threejs里面的vector3源码解析
// File:src/math/Vector3.js /** * @author mrdoob / http://mrdoob.com/ * @author *kile / http://kile. ...
- AttackEnemy人物攻击判断
AttackEnemy人物攻击判断 /// <param name="attackArea">攻击范围</param> /// <param name ...
- [C++][代码库]Vector3空间向量类
本文用C++实现一个简单的Vector3类的功能,暂时有的功能是: 1 + - * /算术运算 2 向量的数量积,又叫:点乘 3 向量的向量积,又叫:叉乘 4 向量单位化(normalization) ...
- Input gameobject vector3 c#
Input类中的常用方法 bool w=Input.GetKey(KeyCode.W);//检测是否按下键盘W Input.GetKeyDown(KeyCode.W);//表示检测按下时 Input. ...
- 【重要】攻击动作时间段判断~使用动画time比较动画length和使用一个变量数组做延迟
using UnityEngine; using System.Linq; using System.Collections.Generic; [RequireComponent(typeof(Cha ...
随机推荐
- JavaScript 中有关时间对象的方法
ECMAScript中的Date类型是在早期 Java 中的 Java.unile.Date 类基础上构建的.为此 Date 类型使用自 UTC (Coordinated Universal Time ...
- android.widget.RadioButton 单选按钮(转)
大家好,我们今天这一节要介绍的是RadioGroup 的组事件.RadioGroup 可将各自不同的RadioButton ,设限于同一个Radio 按钮组,同一个RadioGroup 组里的按钮,只 ...
- jQuery实现图片伦播效果(淡入淡出+左右切换)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Socket 学习实例
整理一份Socket代码,整理前辈的代码 http://www.cnblogs.com/yellowapplemylove/archive/2011/04/19/2021586.html 直接贴代码 ...
- C#加密算法总结
C#加密算法总结 MD5加密 /// <summary> /// MD5加密 /// </summary> /// <param name="strPwd&qu ...
- Unable to start activity ComponentInfo{com.first/com.first.Game}
原因一: xxx的错误,若为R.layout.main 那么应该是main.xml文件中的标签 使用错误,最常见的而且编译器不会提示的错误就是 android:name 和android:id 两者 ...
- 基础学习day01--JAVA入门和JDK的安装与配置
一.软件是什么 软件按照一定顺序组成的计算机指令和数据集合. 二.什么是软件开发 软件开发是使用计算机的语言制作的软件.如迅雷,Windows系统,Linux,QQ等. 三.DOS常用命令 cd..: ...
- Android Service使用拾遗[阿里工程师分享]
Service作为android的四大组件之一常用来帮助我们完成一些需要放在后台处理的任务,通过startService和bindService两种方式被调用.因为Service也是在主线程中运行的, ...
- [android] 手机卫士自定义控件的属性
上一节完成的自定义组合控件,灵活性不够,控件的显示信息上,仿照系统属性,自定义自己的属性 上一节组合控件SettingItemView中有三个控件,分别是TextView大标题,TextView描述, ...
- 选择排序(java版)
public class SelectSortTest { public static void selectSort(int[] source) { for (int i = 0; i < s ...