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 ...
随机推荐
- SQL SERVER与ORACLE的几点区别
1.数据类型不同. sql server 的数据类型 int ,smallint ,char,varchar,nchar,nvarchar,ntext,datetime,smalldatet ...
- mysql python pymysql模块 增删改查 插入数据 介绍 commit() execute() executemany() 函数
import pymysql mysql_host = '192.168.0.106' port = 3306 mysql_user = 'root' mysql_pwd = ' encoding = ...
- mysql python pymysql模块 增删改查 查询 fetchone
import pymysql mysql_host = '192.168.0.106' port = 3306 mysql_user = 'root' mysql_pwd = ' encoding = ...
- Linux发展历史图
Linux发展历史图 http://futurist.se/gldt/wp-content/uploads/12.10/gldt1210.svg
- MySQL管理之道:性能调优、高可用与监控》迷你书
MySQL管理之道:性能调优.高可用与监控>迷你书 MYSQL5.5.X主要改进 1.默认使用innodb存储引擎2.充分利用CPU多核处理能力3.提高刷写脏页数量和合并插入数量,改善I/O4. ...
- excel用法
1:求大于某一值的个数:使用COUNTIF(区间,标准) 要大写 =COUNTIF(B2:B48,">=95") 2:求某一区间的个数用:大区间个数减小区间个数 =CO ...
- [django实践]投票app
code: https://github.com/lannyMa/toupiao polls app介绍 这个例子来源于django官网,恰好2.x版本有中文版. https://docs.djang ...
- hdu1181 (变形课)简单地dfs
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/F Description 呃......变形课上Harr ...
- 转载一篇debug文章
http://versprite.com/og/ios-reverse-engineering-part-two-debugging-and-tracing-with-lldb/ iOS Revers ...
- Windows程序自启动方法汇总
文件夹 一.当前用户专有的启动文件夹 二.对所有用户有效的启动文件夹 三.Load注册键 四.Userinit注册键 五.Explorer\Run注册键 六.RunServicesOnce注册键 七. ...