版本 |
作者 |
参与者 |
完成日期 |
备注 |
UnityAPI_Vector3_V01_1.0 |
严立钻 |
|
2020.07.06 |
|
|
|
|
|
|
立钻哥哥:Unity是一个入门快、提高难的游戏引擎,想要提升能力,至少需要越过3道坎:API+Shader+综合能力;++1、API的积累:对API的合理利用不仅可以减轻自己的编码负担,而且往往可以提高程序的运行效率;这也是钻哥开始“Unity API”独立打造分类的初衷; ++2、Shader编程:想要做出一款精品游戏往往需要有高效的Shader的支持;Unity提供了一套改良的“Shader Lab”系统,优化了繁杂的“Open GL”编程; ++3、综合能力(技术+业务+管理):一款产品的制作除了功能编程外,往往会涉及很多其他领域,例如产品架构、UI交互设计、模型制作等,作为主要的编程人员,对其他相关领域的了解程序往往会影响到产品制作直至最后的产品体验; ++++立钻哥哥一直在推动【VR云游戏=Unity+SteamVR+云技术+5G+AI】,这个只是一个引子,抛砖引玉让大家对整个知识体系有一个明确的落地方向,宝宝们可以根据自己的兴趣方向进行拓展:比如Unity这里是指一种“3D游戏引擎”,也可拓展至“UE4、Cocos2dx”等游戏引擎;SteamVR是一种跨硬件解决方案,也可拓展至“VRTK”等第三方插件;“云技术+5G”是一种跨平台解决方案的核心技术,同样可拓展至其他平台解决方案;AI也是一种先进技术的举例,也可以拓展至任何一种前沿技术; |
++++【Unity API】分类:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html
++++【Unity开发基础】分类:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html
++++【Linux系统编程】分类:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html
++++【C++C铸就生存利器】分类:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html
++++【人工智能AI2026】分类:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html
++++【立钻哥哥CSDN空间】:https://blog.csdn.net/VRunSoftYanlz/
#Vector3三维向量 |
#Vector3三维向量++A1、Description描述++B2、Variables变量++C3、Public Function共有函数++D4、Message消息 |
#A1、Description描述 |
++++这个结构用于在Unity传递3D位置和方向;它也包含做些普通向量运算的函数;
#B2、Static Variables静态变量 |
++B2、Static Variables静态变量++++B2.1、back++++B2.2、down++++B2.3、forward++++B2.4、left++++B2.5、one++++B2.6、right++++B2.7、up++++B2.8、zero++++B2.9、YanlzXREngine.Vector3.StaticVariables |
++B2.1、back |
static Vector3 back; |
++++写Vector3(0,0,-1)的简码,也就是向z轴负方向;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{
void MyTestFunc(){ transform.position += Vector3.back * Time.deltaTime; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzVector3{} |
++B2.2、down |
static Vector3 down; |
++++写Vector3(0,-1,0)的简码,也就是向y轴负方向;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{
void MyTestFunc(){ //transform.position += Vector3.back * Time.deltaTime; transform.position += Vector3.down * Time.deltaTime; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzVector3{} |
++B2.3、forward |
static Vector3 forward; |
++++是Vector3(0,0,1)的简写,也就是向z轴;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{
void MyTestFunc(){ //transform.position += Vector3.back * Time.deltaTime; //transform.position += Vector3.down * Time.deltaTime; transform.position += Vector3.forward * Time.deltaTime; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzVector3{} |
++B2.4、left |
static Vector3 left; |
++++是Vector3(-1, 0, 0)的简写,也就是向x轴负方向;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{
void MyTestFunc(){ //transform.position += Vector3.back * Time.deltaTime; //transform.position += Vector3.down * Time.deltaTime; //transform.position += Vector3.forward * Time.deltaTime; transform.position += Vector3.left * Time.deltaTime; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzVector3{} |
++B2.5、one |
static Vector3 one; |
++++是Vector3(1,1,1)的简码;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{
void MyTestFunc(){ transform.position = Vector3.one; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzVector3{} |
++B2.6、right |
static Vector3 right; |
++++是Vector3(1,0,0)的简码,也就是向x轴;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{
void MyTestFunc(){ //transform.position += Vector3.back * Time.deltaTime; //transform.position += Vector3.down * Time.deltaTime; //transform.position += Vector3.forward * Time.deltaTime; //transform.position += Vector3.left * Time.deltaTime; transform.position += Vector3.right * Time.deltaTime; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzVector3{} |
++B2.7、up |
static Vector3 up; |
++++是Vector3(0,1,0)的简写,也就是向y轴;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{
void MyTestFunc(){ //transform.position += Vector3.back * Time.deltaTime; //transform.position += Vector3.down * Time.deltaTime; //transform.position += Vector3.forward * Time.deltaTime; //transform.position += Vector3.left * Time.deltaTime; //transform.position += Vector3.right * Time.deltaTime; transform.position += Vector3.up * Time.deltaTime; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzVector3{} |
++B2.8、zero |
static Vector3 zero; |
++++是Vector3(0,0,0)的简写;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{
void MyTestFunc(){ //transform.position = Vector3.one; transform.position = Vector3.zero; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzVector3{} |
#C3、Variables变量 |
++C3、Variables变量++++C3.1、magnitude++++C3.2、normalized++++C3.3、sqrMagnitude++++C3.4、this[int]++++C3.5、x++++C3.6、y++++C3.7、z++++C3.8、YanlzXREngine.Vector3.Variables |
++C3.1、magnitude |
float magnitude; |
++++返回向量的长度(只读);
++++向量的长度是(x*x + y*y + z*z)的平方根;
++++如果需要比较一些向量的长度,可以比较它们长度的平方,使用sqrMagnitude(计算平方很快);
++C3.2、normalized |
Vector3 normalized; |
++++返回向量的长度为1(只读);
++++当归一化后,向量保持同样的方向,但是长度变为1.0;
++++注意:当前向量不能改变,而是返回一个新的归一化的向量;如果想归一化当前向量,使用Normalize函数;
++++如果这个向量太小而不能被归一化,一个零向量将会被返回;
++C3.3、sqrMagnitude |
float sqrMagnitude; |
++++返回这个向量的长度的平方(只读);
++++一个向量V的长度计算方法是Mathf.Sqrt(Vector3.Dot(v,v));然而,sqrt计算是相当复杂的,需要更长的时间比正常执行算术操作;计算长度平方来代替直接计算长度速度更快,除掉开根号计算是基本相同的;如果只是使用大小比较的距离,那么同样可以比较平方长度大小来比较距离,得到相同的结果;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Transform other; public float closeDistance = 5.0F;
void Update(){ if(other){ Vector3 offset = other.position - transform.position; float sqrLen = offset.sqrMagnitude; if(sqrLen < closeDistance * closeDistance){ Debug.Log(“立钻哥哥:The other transform is close to me!”); } //立钻哥哥:if(){} } //立钻哥哥:if(other){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzVector3{} |
++C3.4、this[int] |
float this[int]; |
++++使用[0],[1],[2]分别访问组件x,y,z组件;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Vector3 p;
void MyTestFunc(){ p[1] = 5; } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzVector3{} |
++C3.5、x |
float x; |
++++向量的X组件;
++C3.6、y |
float y; |
++++向量的Y组件;
++C3.7、z |
float z; |
++++向量的Z组件;
#D4、Constructors构造器 |
++D4、Constructors构造器++++D4.1、Vector3++++D4.2、YanlzXREngine.Vector3.Constructors |
++D4.1、Vector3 |
Vector3(float x, float y, float z);Vector3(float x, float y) |
++++创建一个新的具有给定x,y,z组件的向量;
#E5、Functions函数 |
++E5、Functions函数++++E5.1、Set++++E5.2、ToString++++E5.3、YanlzXREngine.Vector3.Functions |
++E5.1、Set |
void Set(float new_x, float new_y, float new_z); |
++++设置现有的Vector3的x、y、z组件;
++E5.2、ToString |
string ToString();string ToString(string format); |
++++返回该向量一个格式化好的字符串;
#F6、Static Functions静态函数 |
++F6、Static Functions++++F6.1、Angle++++F6.2、ClampMagnitude++++F6.3、Cross++++F6.4、Distance++++F6.5、Dot++++F6.6、Lerp++++F6.7、LerpUnclamped++++F6.8、Max++++F6.9、Min++++F6.10、MoveTowards++++F6.11、Normalize++++F6.12、OrthoNormalize++++F6.13、Project++++F6.14、ProjectOnPlane++++F6.15、Reflect++++F6.16、RotateTowards++++F6.17、Scale++++F6.18、Slerp++++F6.19、SlerpUnclamped++++F6.20、SmoothDamp++++F6.21、YanlzXREngine.Vector3.StaticFunctions |
++F6.1、Angle |
static float Angle(Vector3 from, Vector3 to); |
++++[from]:角度从这一向量扩展开;
++++[to]:角度扩展至这一向量;
++++由from和to两向量返回一个角度;形象的说,from和to的连线和它们一个指定轴向的夹角;
++++返回的角度总是两个向量之间的锐角(也就是说,它们之间2个可能的角度中较小的那个,不大于180度);
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Transform target;
void Update(){ Vector3 targetDir = target.position - transform.position; Vector3 forward = transform.forward; float angel = Vector3.Angle(targetDir, forward);
if(angle < 5.0F){ Debug.Log(“立钻哥哥:Close.”); } //立钻哥哥:if(){}
} //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.2、ClampMagnitude |
static Vector3 ClampMagnitude(Vector3 vector, float maxLength); |
++++返回原向量的拷贝,并且它的模最大不超过maxLength所指示的长度;
++++也就是说:限制向量长度到一个特定的长度;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Vector3 centerPt; public float radius;
void Update(){ Vector3 movement = new Vector3(Input.GetAxis(“Horizontal”), 0, Input.GetAxis(“Vertical”)); Vector3 newPos = transform.position + movement; Vector3 offset = newPos - centerPt;
transform.position = centerPt + Vector3.ClampMagnitude(offset, radius); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.3、Cross |
static Vector3 Cross(Vector3 lhs, Vector3 rhs); |
++++两个向量的交叉乘积;
++++两个向量的叉积乘积结果在垂直于两个输入向量的三分之一向量;结果的大小等于两个输入相乘,然后乘以输入向量之间的角度的正弦值;可以确定的方向的结果向量使用“左手法则”;
++++左手法则应用于Cross(a,b);
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{
Vector3 MyGetNormal(){ Vector3 side1 = b - a; Vector3 side2 = c - a;
return Vector3.Cross(side1, side2).normalized; } //立钻哥哥:Vector3 MyGetNormal(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.4、Distance |
static float Distance(Vector3 a, Vector3 b); |
++++返回a和b之间的距离;
++++Vector3.Distance(a,b)等同于(a-b).magnitude;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Transform other;
void MyTestFunc(){ if(other){ float dist = Vector3.Distance(other.position, transform.position); Debug.Log(“立钻哥哥:Distance to other: ” + dist); } //立钻哥哥:if(other){} } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.5、Dot |
static float Dot(Vector3 lhs, Vector3 rhs); |
++++两个向量的点乘积;
++++点积时一个浮点型的值,两个向量的长度相乘,然后乘以它们之间夹角的余弦值;
++++对于normalized向量,如果指向在完全相同的方向,Dot返回1;如果指向完全相反的方向,返回-1;对于其他的情况返回一个数(例如:如果是垂直的Dot返回0);
++++如果点乘的结果为0,那么这两个向量互相垂直;
++++如果结果大于0,那么这两个向量的夹角小于90度,方向基本相同;
++++如果结果小于0,那么这两个向量的夹角大于90度,方向基本相反;
++++点乘的结果就是两个向量的模相乘,然后再与这两个向量的夹角的余弦值相乘;或对应分量的乘积之和;
++++lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z或者|lhs|*|rhs|*COS(lhs,rhs);
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Transform other;
void Update(){ if(other){ Vector3 forward = transform.TransformDirection(Vector3.forward); Vector3 toOther = other.position - transform.position;
if(Vector3.Dot(forward, toOther) < 0){ Debug.Log(“立钻哥哥:The other transform is behind me!”); } //立钻哥哥:if(Vector3.Dot()){} } //立钻哥哥:if(other){} } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.6、Lerp |
static Vector3 Lerp(Vector3 from, Vector3 to, float t); |
++++两个向量之间的线性插值;
++++按照分数t在from和to之间插值;这是最常用的寻找一点沿一条线的两个端点之间一些分数的方式(例如:在那些点之间逐渐移动一个对象);这分数是在范围[0 ... 1];t是夹在[0 ... 1]之间,当t=0时,返回from,当t=1时,返回to;当t=0.5返回from和to的中间点;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Transform startMarker; public Transform endMarker; public float speed = 1.0F; private float startTime; private float journeyLength; public Transform target; public float smooth = 5.0F;
void Start(){ startTime = Time.time; journeyLength = Vector3.Distance(startMarker.position, endMarker.position); } //立钻哥哥:void Start(){}
void Update(){ float distCovered = (Time.time - startTime) * speed; float fracJourney = distCovered / journeyLength; transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.7、LerpUnclamped |
public static Vector3 LerpUnclamped(Vector3 a, Vector3 b, float t); |
++++在两个向量之间插值;改插值t在小于0或大于1时的返回值不会被限制;
++++向量a和b之间根据t插值;通常用来在两点连线之间查找某一个点(例如:移动一个对象在两点之间渐变);
++++当t=0返回a,当t=1返回b;当t=0.5返回a和b之间中间的点;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Transform TargetRed; public Transform TargetGreen; public Transform TargetBlue;
void Update(){ TargetGreen.position = Vector3.Lerp(TargetRed.position, TargetBlue.position, Lerp); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.8、Max |
static Vector3 Max(Vector3 lhs, Vector3 rhs); |
++++返回一个由两个向量的最大组件组成的向量;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Vector3 a = new Vector3(1, 2, 3); public Vector3 b = new Vector3(4, 3, 2);
void MyTestFunc(){ Debug.Log(Vector3.Max(a, b)); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.9、Min |
static Vector3 Min(Vector3 lhs, Vector3 rhs); |
++++返回一个由两个向量的最小组件组成的向量;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Vector3 a = new Vector3(1, 2, 3); public Vector3 b = new Vector3(4, 3, 2);
void MyTestFunc(){ //Debug.Log(Vector3.Max(a, b)); Debug.Log(Vector3.Min(a, b)); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.10、MoveTowards |
static Vector3 MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta); |
++++当前的地点移向目标;
++++这个函数的返回值是一个点maxDistanceDelta单位更接近于目标/点沿着当前的和目标之间的线;如果目标是比maxDistanceDelta/然后返回值将等于目标接近(即移动不会超过目标);maxDistanceDelta负值可以用来从目标推开该向量;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Transform target; public float speed;
void Update(){ float step = speed * Time.deltaTime; transform.position = Vector3.MoveTowards(transform.position, target.position, step); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.11、Normalize |
Vector3 Normalize(Vector3 value);Vector3 Normalize(); |
++++使向量的长度为1;
++++当归一化的,一个向量保持相同的方向,但它的长度为1.0;
++++注意:这个函数将改变当前向量,如果想保持当前的向量不改变,使用normalized变量;
++++如果这个向量太小而不能被归一化,将返回零向量;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{
void MyTestFunc(){ Debug.Log(Vector3.Normalize(new Vector3(6,3,2))); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzVector3{}
|
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{
void Update(){ Vector3 tem = Target.position; tem.Normalize(); Target.position = tem; } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.12、OrthoNormalize |
public static void OrthoNormalize(ref Vector3 normal, ref Vector3 tangent);public static void OrthoNormalize(ref Vector3 normal, ref Vector3 tangent, ref Vector3 binormal); |
++++使向量归一化并且彼此相互垂直;
++++归一化normal,规范化tangent并且确保垂直于normal(就是两者之间的角度为90度);
++++归一化normal,归一化tangent并且确保垂直于normal;归一化binormal并确保它到normal和tangent两者之间相互垂直;
++++在标准的XYZ轴系统中通常指定了坐标空间中的点;然而,作为“轴”解释任何三个向量,如果他们都归一化(即,大小是1)和正交(即,相互垂直的);
++++创建自己的坐标轴是很有用的,如果想要缩放在任意方向的网格,而不是只是沿XYZ轴,可以将顶点转换到自己的坐标系统,规范它们的尺寸,然后变换回来;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Vector3 stretchAxis; public float stretchFactor = 1.0F; private MeshFilter mf; private Vector3[] origVerts; private Vector3[] newVerts; private Vector3 basisA; private Vector3 basisB; private Vector3 basisC;
void Start(){ mf = GetComponent<MeshFilter>(); origVerts = mf.mesh.vertices; newVerts = new Vector3[origVerts.Length]; } //立钻哥哥:void Start(){}
void Update(){ basisA = stretchAxis; Vector3.OrthoNormalize(ref basisA, ref basisB, ref basisC);
Matrix4x4 toNewSpace = new Matrix4x4(); toNewSpace.SetRow(0, basisA); toNewSpace.SetRow(1, basisB); toNewSpace.SetRow(2, basisC); toNewSpace[3, 3] = 1.0F;
Matrix4x4 scale = new Matrix4x4(); scale[0, 0] = stretchFactor; scale[1, 1] = 1.0F / stretchFactor; scale[2, 2] = 1.0F / stretchFactor; scale[3, 3] = 1.0F;
Matrix4x4 fromNewSpace = toNewSpace.transpose; Matrix4x4 trans = toNewSpace * scale * fromNewSpace;
int i = 0; while(i < origVerts.Length){ newVerts[i] = trans.MultiplyPoint3x4(origVerts[i]); i++; }
mf.mesh.vertices = newVerts;
} //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.13、Project |
static Vector3 Project(Vector3 vector, Vector3 onNormal); |
++++投影一个向量到另一个向量;
++++要理解向量投影,想象那onNormal搁在其方向的一条线上;在某处沿着这条路线将是向量末端的最近点;投影是重新onNormal,以便达到在线上的点;
++++函数将返回一个零向量,如果onNormal接近零;
++++使用投影的一个例子是:一个轨道式枪要使其可能地滑动到接近目标对象;目标沿轨道方向的投影可以通过施加力到刚体来移动枪;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{
void MySlide(Transform target, Vector3 railDirection){ Vector3 heading = target.position - transform.position; Vector3 force = Vector3.Project(heading, railDirection); rigidbody.AddForce(force); } //立钻哥哥:void MySlide(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.14、ProjectOnPlane |
public static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal); |
++++投影向量到一个平面上,该平面由垂直到该法线的平面定义;
++F6.15、Reflect |
static Vector3 Reflect(Vector3 inDirection, Vector3 inNormal); |
++++沿着法线反射向量;
++++该inNormal向量定义的平面(平面的法线是垂直于它的表面上的向量);该间接向量被视为一个方向的箭头来在该平面上;返回的值是间接的相等的幅度,但其反射方向的向量;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Transform originalObject; public Transform reflectedObject;
void Update(){ reflectedObject.position = Vector3.Reflect(originalObject.position, Vector3.right); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.16、RotateTowards |
static Vector3 RotateTowards(Vector3 current, Vector3 target, float maxRadiansDelta, float maxMagnitudeDelta); |
++++当前的向量转向目标;
++++这个函数类似于MoveTowards除了将向量被视为一个方向,而不是一个位置上;当前向量将被旋转朝向目标方向由maxRadiansDelta的角度,虽然会恰好落在目标,而不是超过;如果当前的大小和目标的是不同的,那么结果的幅度将被线性地旋转过程中进行插值;如果一个负值用于maxRadiansDelta,向量会转离目标/直到它指向完全相反的方向,然后停止;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Transform target; public float speed;
void Update(){ Vector3 targetDir = target.position - transform.position; float step = speed * Time.deltaTime;
Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0F); Debug.DrawRay(transform.position, newDir, Color.red); transform.rotation = Quaternion.LookRotation(newDir); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.17、Scale |
static Vector3 Scale(Vector3 a, Vector3 b);void Scale(Vector3 scale); |
++++两个向量组件对应相乘;
++++结果每个组件是有相同名字a的组件(a*a)和相同名字b的组件(b*b)分别相乘;
++++使这个向量相同组件的缩放,靠每个组件的相乘;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{
void MyTestFunc(){ Debug.Log(Vector3.Scale(new Vector3(1,2,3), new Vector3(2,3,4))); } //立钻哥哥:void MyTestFunc(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.18、Slerp |
static Vector3 Slerp(Vector3 from, Vector3 to, float t); |
++++两个向量之间的弧形插值;
++++通过t数值在from和to之间插值;这与线性内插之间的不同(即,“线性插值”)是该向量被视为方向而不是空间中的点;返回的向量的方向是由角内插,其大小是from和to的幅度之间进行内插;
++++t的值在[0 ... 1];
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Transform sunrise; public Transform sunset; public float journeyTime = 1.0F; private float startTime;
void Start(){ startTime = Time.time; } //立钻哥哥:void Start(){}
void Update(){ Vector3 center = (sunrise.position + sunset.position) * 0.5F; center -= new Vector3(0, 1, 0);
Vector3 riseRelCenter = sunrise.position - center; Vector3 setRelCenter = sunset.position - center; float fracComplete = (Time.time - startTime) / journeyTime;
transform.position = Vector3.Slerp(riseRelCenter, setRelCenter, fracComplete); transform.position += center;
} //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzVector3{} |
++F6.19、SlerpUnclamped |
public static Vector3 SlerpUnclamped(Vector3 a, Vector3 b, float t); |
++++在两个向量之间球形插值;改插值t在小于0或大于1时的返回值不会被限制;
++++通过t数值在a和b之间插值;这与线性内插之间的不同(lerp)是该向量被视为方向而不是空间中的点;返回的向量的方向是由角内插,向量的长度是from和to的长度之间进行内插;
++F6.20、SmoothDamp |
static Vector3 SmoothDamp(Vector3 current, Vector3 target, Vector3 currentVelocity, float smoothTime, float maxSpeed=Mathf.Infinity, float deltaTime=Time.deltaTime); |
++++[current]:当前位置坐标;
++++[target]:想要达到的位置;
++++[currentVelocity]:当前速度,该值由每次调用该函数时修改;
++++[smoothTime]:达到目标大约花费的时间;一个较小的值将更快达到目标;
++++[maxSpeed]:选择允许限制的最大速度;
++++[deltaTime]:自上次调用这个函数;默认情况下是Time.deltaTime;
++++随着时间的推移,逐渐改变一个向量朝向预期的目标;
++++向量由一些像弹簧阻尼器函数平滑,这将永远不会超过;最常见的用途是平滑跟随摄像机;
using UnityEngine; using System.Collections; using YanlzXREngine;
public class YanlzVector3 : MonoBehaviour{ public Transform target; public float smoothTime = 0.3F; private Vector3 velocity = Vector3.zero;
void Update(){ Vector3 targetPosition = target.TransformPoint(new Vector3(0, 5, -10)); transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime); } //立钻哥哥:void Update(){}
} //立钻哥哥:public class YanlzVector3{} |
#G7、立钻哥哥对Vector3类的拓展 |
++++【Unity API】分类:https://blog.csdn.net/vrunsoftyanlz/category_7637520.html
++++【Unity开发基础】分类:https://blog.csdn.net/vrunsoftyanlz/category_7309057.html
++++【Linux系统编程】分类:https://blog.csdn.net/vrunsoftyanlz/category_9694767.html
++++【C++C铸就生存利器】分类:https://blog.csdn.net/vrunsoftyanlz/category_9325802.html
++++【人工智能AI2026】分类:https://blog.csdn.net/vrunsoftyanlz/category_9212024.html
++++【立钻哥哥CSDN空间】:https://blog.csdn.net/VRunSoftYanlz/
立钻哥哥推荐的拓展学习链接(Link_Url) |
++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz/
++++虚拟现实VR资讯: https://blog.csdn.net/VRunSoftYanlz/article/details/89165846
++++HTC_VIVE开发基础:https://blog.csdn.net/VRunSoftYanlz/article/details/81989970
++++Oculus杂谈:https://blog.csdn.net/VRunSoftYanlz/article/details/82469850
++++Oculus安装使用:https://blog.csdn.net/VRunSoftYanlz/article/details/82718982
++++Unity+SteamVR=>VR:https://blog.csdn.net/VRunSoftYanlz/article/details/88809370
++++Unity减少VR晕眩症:https://blog.csdn.net/VRunSoftYanlz/article/details/89115518
++++SteamVR简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86484254
++++SteamVR脚本功能分析:https://blog.csdn.net/VRunSoftYanlz/article/details/86531480
++++SteamVR2.0开发指南:https://blog.csdn.net/VRunSoftYanlz/article/details/86618187
++++SteamVR2.2.0开发指南:https://blog.csdn.net/VRunSoftYanlz/article/details/88784527
++++SteamVR2.2.0快速入门:https://blog.csdn.net/VRunSoftYanlz/article/details/88833579
++++SteamVR2.2.0交互系统:https://blog.csdn.net/VRunSoftYanlz/article/details/89199778
++++SteamVR2.2.0传送机制:https://blog.csdn.net/VRunSoftYanlz/article/details/89390866
++++SteamVR2.2.0教程(一):https://blog.csdn.net/VRunSoftYanlz/article/details/89324067
++++SteamVR2.2.0教程(二):https://blog.csdn.net/VRunSoftYanlz/article/details/89894097
++++SteamVR_Skeleton_Poser:https://blog.csdn.net/VRunSoftYanlz/article/details/89931725
++++SteamVR实战之PMCore:https://blog.csdn.net/VRunSoftYanlz/article/details/89463658
++++SteamVR/Extras:https://blog.csdn.net/VRunSoftYanlz/article/details/86584108
++++SteamVR/Input:https://blog.csdn.net/VRunSoftYanlz/article/details/86601950
++++OpenXR简介:https://blog.csdn.net/VRunSoftYanlz/article/details/85726365
++++VRTK杂谈:https://blog.csdn.net/VRunSoftYanlz/article/details/82562993
++++VRTK快速入门(杂谈):https://blog.csdn.net/VRunSoftYanlz/article/details/82955267
++++VRTK官方示例(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82955410
++++VRTK代码结构(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82780085
++++VRTK(SceneResources):https://blog.csdn.net/VRunSoftYanlz/article/details/82795400
++++VRTK_ControllerEvents:https://blog.csdn.net/VRunSoftYanlz/article/details/83099512
++++VRTK_InteractTouch:https://blog.csdn.net/VRunSoftYanlz/article/details/83120220
++++虚拟现实行业应用:https://blog.csdn.net/VRunSoftYanlz/article/details/88360157
++++Steam平台上的VR:https://blog.csdn.net/VRunSoftYanlz/article/details/88960085
++++Steam平台热销VR:https://blog.csdn.net/VRunSoftYanlz/article/details/89007741
++++VR实验:以太网帧的构成:https://blog.csdn.net/VRunSoftYanlz/article/details/82598140
++++实验四:存储器扩展实验:https://blog.csdn.net/VRunSoftYanlz/article/details/87834434
++++FrameVR示例V0913:https://blog.csdn.net/VRunSoftYanlz/article/details/82808498
++++FrameVR示例V1003:https://blog.csdn.net/VRunSoftYanlz/article/details/83066516
++++SwitchMachineV1022:https://blog.csdn.net/VRunSoftYanlz/article/details/83280886
++++PlaySceneManagerV1022:https://blog.csdn.net/VRunSoftYanlz/article/details/83280886
++++Unity5.x用户手册:https://blog.csdn.net/VRunSoftYanlz/article/details/81712741
++++Unity面试题ABC:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++Unity面试题D:https://blog.csdn.net/VRunSoftYanlz/article/details/78630838
++++Unity面试题E:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity面试题F:https://blog.csdn.net/VRunSoftYanlz/article/details/78630945
++++Cocos2dx面试题:https://blog.csdn.net/VRunSoftYanlz/article/details/78630967
++++禅道[zentao]:https://blog.csdn.net/VRunSoftYanlz/article/details/83964057
++++Lua快速入门篇(Xlua拓展):https://blog.csdn.net/VRunSoftYanlz/article/details/81173818
++++Lua快速入门篇(XLua教程):https://blog.csdn.net/VRunSoftYanlz/article/details/81141502
++++Lua快速入门篇(基础概述):https://blog.csdn.net/VRunSoftYanlz/article/details/81041359
++++框架知识点:https://blog.csdn.net/VRunSoftYanlz/article/details/80862879
++++游戏框架(UI框架夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80781140
++++游戏框架(初探篇):https://blog.csdn.net/VRunSoftYanlz/article/details/80630325
++++.Net框架设计:https://blog.csdn.net/VRunSoftYanlz/article/details/87401225
++++从零开始学架构:https://blog.csdn.net/VRunSoftYanlz/article/details/88095895
++++设计模式简单整理:https://blog.csdn.net/vrunsoftyanlz/article/details/79839641
++++专题:设计模式(精华篇):https://blog.csdn.net/VRunSoftYanlz/article/details/81322678
++++U3D小项目参考:https://blog.csdn.net/vrunsoftyanlz/article/details/80141811
++++Unity小游戏算法分析:https://blog.csdn.net/VRunSoftYanlz/article/details/87908365
++++Unity案例(Vehicle):https://blog.csdn.net/VRunSoftYanlz/article/details/82355876
++++UML类图:https://blog.csdn.net/vrunsoftyanlz/article/details/80289461
++++PowerDesigner简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86500084
++++Unity知识点0001:https://blog.csdn.net/vrunsoftyanlz/article/details/80302012
++++Unity知识点0008:https://blog.csdn.net/VRunSoftYanlz/article/details/81153606
++++U3D_Shader编程(第一篇:快速入门篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372071
++++U3D_Shader编程(第二篇:基础夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372628
++++Unity引擎基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78881685
++++Unity面向组件开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78881752
++++Unity物理系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78881879
++++Unity2D平台开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78882034
++++UGUI基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78884693
++++UGUI进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78884882
++++UGUI综合:https://blog.csdn.net/vrunsoftyanlz/article/details/78885013
++++Unity动画系统基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78886068
++++Unity动画系统进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78886198
++++Navigation导航系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78886281
++++Unity特效渲染:https://blog.csdn.net/vrunsoftyanlz/article/details/78886403
++++Unity数据存储:https://blog.csdn.net/vrunsoftyanlz/article/details/79251273
++++Unity中Sqlite数据库:https://blog.csdn.net/vrunsoftyanlz/article/details/79254162
++++WWW类和协程:https://blog.csdn.net/vrunsoftyanlz/article/details/79254559
++++Unity网络:https://blog.csdn.net/vrunsoftyanlz/article/details/79254902
++++Unity资源加密:https://blog.csdn.net/VRunSoftYanlz/article/details/87644514
++++PhotonServer简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86652770
++++编写Photon游戏服务器:https://blog.csdn.net/VRunSoftYanlz/article/details/86682935
++++C#事件:https://blog.csdn.net/vrunsoftyanlz/article/details/78631267
++++C#委托:https://blog.csdn.net/vrunsoftyanlz/article/details/78631183
++++C#集合:https://blog.csdn.net/vrunsoftyanlz/article/details/78631175
++++C#泛型:https://blog.csdn.net/vrunsoftyanlz/article/details/78631141
++++C#接口:https://blog.csdn.net/vrunsoftyanlz/article/details/78631122
++++C#静态类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630979
++++C#中System.String类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630945
++++C#数据类型:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity3D默认的快捷键:https://blog.csdn.net/vrunsoftyanlz/article/details/78630838
++++游戏相关缩写:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++UnityAPI.Rigidbody刚体:https://blog.csdn.net/VRunSoftYanlz/article/details/81784053
++++UnityAPI.Material材质:https://blog.csdn.net/VRunSoftYanlz/article/details/81814303
++++UnityAPI.Android安卓:https://blog.csdn.net/VRunSoftYanlz/article/details/81843193
++++UnityAPI.AndroidJNI安卓JNI:https://blog.csdn.net/VRunSoftYanlz/article/details/81879345
++++UnityAPI.Transform变换:https://blog.csdn.net/VRunSoftYanlz/article/details/81916293
++++UnityAPI.WheelCollider轮碰撞器:https://blog.csdn.net/VRunSoftYanlz/article/details/82356217
++++UnityAPI.Resources资源:https://blog.csdn.net/VRunSoftYanlz/article/details/83155518
++++JSON数据结构:https://blog.csdn.net/VRunSoftYanlz/article/details/82026644
++++CocosStudio快速入门:https://blog.csdn.net/VRunSoftYanlz/article/details/82356839
++++Unity企业内训(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82634668
++++Unity企业内训(第1讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82634733
++++Unity企业内训(第2讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82861180
++++Unity企业内训(第3讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82927699
++++Unity企业内训(第4讲):https://blog.csdn.net/VRunSoftYanlz/article/details/83479776
++++Unity企业内训(第5讲):https://blog.csdn.net/VRunSoftYanlz/article/details/83963811
++++Unity企业内训(第6讲):https://blog.csdn.net/VRunSoftYanlz/article/details/84207696
++++钻哥带您了解产品原型:https://blog.csdn.net/VRunSoftYanlz/article/details/87303828
++++插件
++++计算机组成原理(教材篇):https://blog.csdn.net/VRunSoftYanlz/article/details/82719129
++++5G接入:云计算和雾计算:https://blog.csdn.net/VRunSoftYanlz/article/details/88372718
++++云计算通俗讲义:https://blog.csdn.net/VRunSoftYanlz/article/details/88652803
++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz
--_--VRunSoft:lovezuanzuan--_--
--_--VRunSoft:lovezuanzuan--_--