Unity3D学习笔记(六):三角函数和点乘


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyLook : MonoBehaviour
{
public Transform player;
public float result;
public float distance;
// Use this for initialization
void Start()
{
////向量点乘的数学运算
//Vector3 enemy2Player = player.position - transform.position;
//Vector3 enemyForward = transform.forward;
//result = enemy2Player.x * enemyForward.x + enemy2Player.y * enemyForward.y + enemy2Player.z + enemyForward.z;
//把向量变成单位向量
Vector3 enemy2Player = (player.position - transform.position).normalized;
Vector3 enemyForward = transform.forward;
//计算两个向量之间的夹角
result = Vector3.Dot(enemy2Player, enemyForward);
//计算两个物体之间的距离
distance = Vector3.Distance(player.position, transform.position);
//API:计算两个向量之间的夹角
//Vector3.Angle();
}
// Update is called once per frame
void Update()
{
}
private void OnGUI()
{
//if (result > 0)
//{
// GUILayout.Label("在敌人前方");
//}
//else
//{
// GUILayout.Label("在敌人后方");
//}
if (result > Mathf.Cos( * Mathf.Deg2Rad) && distance < )
{
GUILayout.Label("在扇形范围内:" + Mathf.Acos(result) * Mathf.Rad2Deg + "度");
}
else
{
GUILayout.Label("不在扇形范围内:" + Mathf.Acos(result) * Mathf.Rad2Deg + "度");
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestTrans : MonoBehaviour {
public Transform Target;
public float distance;
private float SkillDistance = ;//扇形距离
private float SkillJiaodu = ;//扇形的角度
// Use this for initialization
void Start () {
////偶然性编程
distance = Vector3.Distance(transform.position, Target.position);//距离
Vector3 norVec = transform.rotation * Vector3.forward;
Vector3 temVec = Target.position - transform.position;
Debug.DrawLine(transform.position, norVec, Color.red);//画出技能释放者面对的方向向量
Debug.DrawLine(transform.position, Target.position, Color.green);//画出技能释放者与目标点的连线
float jiajiao = Mathf.Acos(Vector3.Dot(norVec.normalized, temVec.normalized)) * Mathf.Rad2Deg;
if (distance <= SkillDistance)
{
if (jiajiao <= SkillJiaodu)
{
Debug.Log("在扇形范围内");
}
else
{
Debug.Log("不在扇形范围内");
}
}
} // Update is called once per frame
void Update () { }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CrystalMove : MonoBehaviour {
//public Transform startTrans;
//public float moveSpeed = 1;
//public float rotSpeed = 1;
public float rotateSpeed = ;
//调节上下频率和浮动
public float amplitude = 1f;
public float frequency = 1f;
// Use this for initialization
void Start () { } // Update is called once per frame
void Update () {
// transform.Rotate(Vector3.up, Space.World);
// Vector3 delta = Vector3.up * Mathf.Sin(Time.time) * moveSpeed*0.25F;
// transform.position = startTrans.position + delta;
transform.Rotate(Vector3.up * Time.deltaTime * rotateSpeed);
float sin = Mathf.Sin(Time.time * frequency) * amplitude;
transform.Translate(Vector3.up * sin, Space.World);
}
}
Unity3D学习笔记(六):三角函数和点乘的更多相关文章
- java之jvm学习笔记六-十二(实践写自己的安全管理器)(jar包的代码认证和签名) (实践对jar包的代码签名) (策略文件)(策略和保护域) (访问控制器) (访问控制器的栈校验机制) (jvm基本结构)
java之jvm学习笔记六(实践写自己的安全管理器) 安全管理器SecurityManager里设计的内容实在是非常的庞大,它的核心方法就是checkPerssiom这个方法里又调用 AccessCo ...
- Learning ROS for Robotics Programming Second Edition学习笔记(六) indigo xtion pro live
中文译著已经出版,详情请参考:http://blog.csdn.net/ZhangRelay/article/category/6506865 Learning ROS for Robotics Pr ...
- Typescript 学习笔记六:接口
中文网:https://www.tslang.cn/ 官网:http://www.typescriptlang.org/ 目录: Typescript 学习笔记一:介绍.安装.编译 Typescrip ...
- python3.4学习笔记(六) 常用快捷键使用技巧,持续更新
python3.4学习笔记(六) 常用快捷键使用技巧,持续更新 安装IDLE后鼠标右键点击*.py 文件,可以看到Edit with IDLE 选择这个可以直接打开编辑器.IDLE默认不能显示行号,使 ...
- Go语言学习笔记六: 循环语句
Go语言学习笔记六: 循环语句 今天学了一个格式化代码的命令:gofmt -w chapter6.go for循环 for循环有3种形式: for init; condition; increment ...
- 【opencv学习笔记六】图像的ROI区域选择与复制
图像的数据量还是比较大的,对整张图片进行处理会影响我们的处理效率,因此常常只对图像中我们需要的部分进行处理,也就是感兴趣区域ROI.今天我们来看一下如何设置图像的感兴趣区域ROI.以及对ROI区域图像 ...
- Linux学习笔记(六) 进程管理
1.进程基础 当输入一个命令时,shell 会同时启动一个进程,这种任务与进程分离的方式是 Linux 系统上重要的概念 每个执行的任务都称为进程,在每个进程启动时,系统都会给它指定一个唯一的 ID, ...
- # go微服务框架kratos学习笔记六(kratos 服务发现 discovery)
目录 go微服务框架kratos学习笔记六(kratos 服务发现 discovery) http api register 服务注册 fetch 获取实例 fetchs 批量获取实例 polls 批 ...
- Spring Boot 学习笔记(六) 整合 RESTful 参数传递
Spring Boot 学习笔记 源码地址 Spring Boot 学习笔记(一) hello world Spring Boot 学习笔记(二) 整合 log4j2 Spring Boot 学习笔记 ...
- unity3d学习笔记(一) 第一人称视角实现和倒计时实现
unity3d学习笔记(一) 第一人称视角实现和倒计时实现 1. 第一人称视角 (1)让mainCamera和player(视角对象)同步在一起 因为我们的player是生成的,所以不能把mainCa ...
随机推荐
- fiddler抓包工具使用
此工具用于抓取302等看不到的包. 设置: 步骤一 步骤二 重启fiddler软件,设置才有效. 设置谷歌浏览器,使浏览器的访问都经过fiddler.(fiddler就成了代理了)设置如下 隐藏图片的 ...
- ul li剧中对齐
html: <div class="footernav"> <ul> <li>首页</li> <li>文章</li ...
- PAT Counting Leaves[一般]
1004 Counting Leaves (30)(30 分) A family hierarchy is usually presented by a pedigree tree. Your job ...
- div 在css中透明度怎么调?
可以用这个属性:opacity: 0.95;opacity为属性,0.95为值(其中值的范围在0~1之间) 参考:https://zhidao.baidu.com/question/689118188 ...
- ajax课2JSON
1.ajax优点: a.页面无刷新 b.用户体验度较好,不会打断用户操作 c.按需求获取数据,不需要返回一个完整的页面 d.是标准的技术,不需要安装任何的插件 应用场景:注册.表格数据的增删改 2.J ...
- mybitis学习笔记
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-// ...
- dedecms开启多站点
dedecms开启多站点后,填写域名才能正确的地址 if ( ! function_exists('GetFileUrl')) { function GetFileUrl($aid,$typeid,$ ...
- Rpgmakermv(4 )doc of TerraxLights
我只做简要翻译. To activate the script in an area, do the following: 1. Put an event switch into the map. 2 ...
- bind,live,delegate
.live() 到目前为止,一切似乎很完美.可惜,事实并非如此.因为.live()方法并不完美,它有如下几个主要缺点: $()函数会找到当前页面中的所有td元素并创建jQuery对象,但在确认事件目标 ...
- Linux 使用系统ISO制作yum源
关于linux安装问题,大多数情况下 系统开发完成之后,需要部署到生产机器上,客户提供的机器预装好了操作系统,但是都是内网环境 与外网都是物理隔绝的,那么 在搭建生产环境时需要安装相关软件时,如果自己 ...