//这两个意义未知
public const float kEpsilon = 1E-05F;
public const float kEpsilonNormalSqrt = 1E-15F;
public float x;
public float y;
public float z;
public Vector3(float x, float y);
public Vector3(float x, float y, float z);
//下标[0][1][2]代表x,y,z Vector3 v3 = new Vector3(0, 0, 0); v3[0] = 1;
public float this[int index] { get; set; }
public static Vector3 right { get; }
public static Vector3 left { get; }
public static Vector3 up { get; }
public static Vector3 down { get; }
public static Vector3 back { get; }
public static Vector3 forward { get; }
public static Vector3 one { get; }
public static Vector3 zero { get; }
// Shorthand for writing Vector3(float.NegativeInfinity, float.NegativeInfinity,
// float.NegativeInfinity). 负无穷 意义何在,用在什么地方?
public static Vector3 negativeInfinity { get; }
// Shorthand for writing Vector3(float.PositiveInfinity, float.PositiveInfinity,
// float.PositiveInfinity). 正无穷
public static Vector3 positiveInfinity { get; }
public float sqrMagnitude { get; }//向量长度平方
public Vector3 normalized { get; }//向量单位向量
public float magnitude { get; }//向量长度
public static float Angle(Vector3 from, Vector3 to);
//钳制求模 返回向量 vector 的副本,长度不超过 maxLength
public static Vector3 ClampMagnitude(Vector3 vector, float maxLength);
public static Vector3 Cross(Vector3 lhs, Vector3 rhs);
public static float Distance(Vector3 a, Vector3 b);
public static float Dot(Vector3 lhs, Vector3 rhs);
//钳制性的线性差值,返回值限定在a和b之间
public static Vector3 Lerp(Vector3 a, Vector3 b, float t);
//非钳制性的线性差值,返回值会超过a和b的范围
public static Vector3 LerpUnclamped(Vector3 a, Vector3 b, float t);
//某向量大小
public static float Magnitude(Vector3 vector);
//返回由两个向量的最大分量组成的向量。lhs(1, 2, 3),rhs(3, 5, 1),返回(3,5,3)
public static Vector3 Max(Vector3 lhs, Vector3 rhs);
public static Vector3 Min(Vector3 lhs, Vector3 rhs);
//计算当前和目标指定的点之间的位置,移动不超过 maxDistanceDelta 指定的距离。
//与Lerp()的区别,第三个参数 Lerp()指的是比例,MoveTowards()指的是具体距离
//current(1, 0, 0),target(10, 0, 0),距离为9,那么maxDistanceDelta范围就是(-9,9);
//大于9,取9,小于-9,取-9;若:取0,返回(1,0,0);取1,返回(2,0,0);取-1,返回(0,0,0);移动不会超过目标,maxdistancedelta为负值时,可以用来从目标推开该向量
public static Vector3 MoveTowards(Vector3 current, Vector3 target, float maxDistanceDelta);
//某向量单位向量
public static Vector3 Normalize(Vector3 value);
//归一化 normal,归一化 tangent并且确保它垂直于 normal。
//归一化 binormal 并确保它到 normal和tangent两者之间相互垂直。
public static void OrthoNormalize(ref Vector3 normal, ref Vector3 tangent, ref Vector3 binormal);
//归一化 normal,归一化 tangent 并且确保它垂直于 normal
public static void OrthoNormalize(ref Vector3 normal, ref Vector3 tangent);
// vector 在 onNormal 上的投影
public static Vector3 Project(Vector3 vector, Vector3 onNormal);
//投影 vector 到以 planeNormal 为法向量的平面上
public static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal);
//将一个向量反射出由法线定义的平面。
public static Vector3 Reflect(Vector3 inDirection, Vector3 inNormal);
//参考 MoveTowards(),最后一个参数还没理解
public static Vector3 RotateTowards(Vector3 current, Vector3 target, float maxRadiansDelta, float maxMagnitudeDelta);
//将两个向量按分量相乘。a(1, 2, 3),b(3, 5, 1),返回(3,10,3)
public static Vector3 Scale(Vector3 a, Vector3 b);
//带符号角度,暂未研究透
public static float SignedAngle(Vector3 from, Vector3 to, Vector3 axis);
//球面插值两个向量。 见图组1、图组2
public static Vector3 Slerp(Vector3 a, Vector3 b, float t);
//球面插值两个向量,不钳制。 见图组3
public static Vector3 SlerpUnclamped(Vector3 a, Vector3 b, float t);
//光滑阻尼 参数还没有完全理解
public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, [DefaultValue("Mathf.Infinity")] float maxSpeed, [DefaultValue("Time.deltaTime")] float deltaTime);
public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime, float maxSpeed);
public static Vector3 SmoothDamp(Vector3 current, Vector3 target, ref Vector3 currentVelocity, float smoothTime);
public static float SqrMagnitude(Vector3 vector);
public void Scale(Vector3 scale);
// Vector3 vector = Vector3.zero; vector.Set(0.1f, 0.2f, 0.3f);
public void Set(float newX, float newY, float newZ);
//为这个向量返回格式化良好的字符串。 transform.position.ToString("0.000")
public string ToString(string format);
public override string ToString();
public static Vector3 operator +(Vector3 a, Vector3 b);
public static Vector3 operator -(Vector3 a);
public static Vector3 operator -(Vector3 a, Vector3 b);
public static Vector3 operator *(Vector3 a, float d);
public static Vector3 operator *(float d, Vector3 a);
public static Vector3 operator /(Vector3 a, float d);
public static bool operator ==(Vector3 lhs, Vector3 rhs);
public static bool operator !=(Vector3 lhs, Vector3 rhs);
没什么干货,仅用于自己加深记忆。namespace UnityEngine{ public struct Vector3 : IEquatable<Vector3> { //这两个意义未知 public const float kEpsilon = 1E-05F; public const float kEpsilonNormalSqrt = 1E-15F; public float x;
1.
Vector
表示向量、矢量的意思,含有大小和方向;
Vector
3 由名可得表示三维向量,包含想 x, y, z 三个分量(供自学记录)。2.简单理解
Vector
3就是相当于一个类,可直接new. 其中xyz三维坐标系可参考左手坐标系(拇指指向自己方向)。一般在使用中transform下的position、scale、rotation等属性都可以通过设置
Vector
3的值来改变其相应的位置、大小(transform详见下篇)。
3.其他方法public static
Vector
3 MoveTow
Vector
3.Angle(trans1.position,trans2.position);
2. SqrMagnitude: 向量的模长平方,比较向量的长度的大小时比magnitude更省性能,因为少个内部开方。
3. ClampMagnitude: 返回向量,长度不会大于设定的length,如果原向量模长小于length,返回向量不变化,但是如...
1、
Vector
3三维向量:表示3D的向量和点。包含位置、方向(朝向)、欧拉角的信息,也包含做些普通向量运算的函数。
2、Quaternion四元数,用于表示旋转,
Unity
内使用Quaternion表示所有旋转。在电脑图形学中用于表示物体的旋转,在
unity
中由x,y,z,w 表示四个值。四元数不会产生万向节死锁并且能够很容易被插值。
在
Unity
里,tranform组件有一个变量名为rot
直接调用position.Set会发现没有用。其实和其本身是结构体有关,要当成一个值类型来看待,因为他全部是在栈中。
transform.position.Set(10,0,0);
改成这样即可:
var tmp = transform.position;
tmp.Set(10, 0, 0);
transform.position = tmp;
<h3>回答1:</h3><br/>
unity
vector
3.smoothdamp是一个
Unity
游戏引擎
中的函数,用于实现平滑移动的效果。这个函数可以接收目标位置、当前位置、当前速度、平滑时间等参数,让物体在指定时间内平滑地移动到目标位置。
<h3>回答2:</h3><br/>
Unity
中的
Vector
3.SmoothDamp是一个用于平滑过渡向量的函数。它可以使物体在一定的时间内,从初始位置平滑的过渡到目标位置,且速度逐步减小,从而更加自然地运动。
在使用
Vector
3.SmoothDamp之前,我们需要定义三个向量:当前位置current、目标位置target和当前速度velocity。目标位置是物体最终要到达的坐标,当前位置是物体当前的坐标,而当前速度则是物体当前的速度。
然后,我们可以通过调用
Vector
3.SmoothDamp函数来平滑过渡目标位置和当前位置。SmoothDamp函数的语法为:
public static
Vector
3 SmoothDamp(
Vector
3 current,
Vector
3 target, ref
Vector
3 currentVelocity, float smoothTime, float maxSpeed = Mathf.Infinity, float deltaTime = Time.deltaTime);
SmoothDamp函数需要传入6个参数,其中包括当前位置,目标位置,当前速度,平滑时间,最大速度和时间增量(可选,默认为Time.deltaTime)。平滑时间是指完全平滑到目标位置所需的时间,最大速度是指物体能够达到的最大速度。
在使用SmoothDamp函数时,我们需要注意以下几点:
一、需要在Update中调用SmoothDamp函数,以保证物体动态更新。
二、平滑时间越大,物体的平滑效果越明显,但同时也会导致物体运动速度减慢。
三、最大速度是一个可选参数,一般情况下不需要设置。
四、物体的运动方向和速度大小由函数自动计算,无需手动设置。
总之,
Vector
3.SmoothDamp函数是一种用于平滑过渡物体移动的方法,可使物体运动更加自然,适用于各种类型的游戏开发。在实际使用过程中需要根据情况调整平滑时间等参数,以达到最佳效果。
<h3>回答3:</h3><br/>
Unity
Vector
3.SmoothDamp是一个用于平滑移动对象的函数。平滑移动是指对象移动时是平缓的,不是突然的,可以通过此函数实现。
在使用
Vector
3.SmoothDamp函数时,我们可以指定当前对象的位置、当前的速度以及目标位置,函数会根据这些参数计算出一个平缓的移动曲线,该曲线可以让对象从当前位置平滑地移动到目标位置。
函数的四个参数是当前位置(current)、目标位置(target)、当前速度(currentVelocity)、运动时间(smoothTime)。其中,当前位置和目标位置是用
Vector
3表示的,当前速度也是使用
Vector
3表示的,在函数的每一帧中会根据当前速度来改变对象的位置,运动时间指平缓移动到目标位置需要的时间,单位是秒。
函数的调用方式为:
Vector
3.SmoothDamp(current, target, ref currentVelocity, smoothTime);
在实际使用时,需要注意几点。首先,函数的时间参数必须是正数,否则会引起错误。其次,向量current、target、currentVelocity的每个元素都需要被初始化,至少为零。
总而言之,
Unity
Vector
3.SmoothDamp函数是一个非常有用的函数,可以帮助我们实现移动效果更平滑、更自然的对象。当我们需要实现一些视觉动画、物理仿真等效果时,可以使用这个函数来实现对象的平滑移动效果,增强场景的真实感和动态感。