unity3d transform rotate3d.rotate和直接改欧拉角的区别

// align Camera
float fRoll = 0.0f; // 不能绕Z轴滚动
// 欧拉角中的绕X轴旋转,对应Mouse Y移动(上下),
float rPitch = Input.GetAxis(&Mouse Y&);
// 欧拉角中的绕Y轴旋转,对应Mouse X移动(左右)
float rYaw = Input.GetAxis(&Mouse X&);
// 鼠标的上下左右移动,转换为主角的旋转欧拉角
// eulerAngles是(yaw, pitch,roll)
// rPitch取负数,是因为Mouse Y向上移动希望是往前看绕X轴旋转反向,像Mouse Y向下是增大绕Y轴旋转正向
Vector3 vecMouse = new Vector3(-rPitch, rYaw, fRoll);
m_camRotateAngles += vecM // m_camRotateAngles是摄像机旋转欧拉角
// 整个摄像机旋转,主角的旋转影响到摄像机旋转(包括上下左右),欧拉角需要一次赋值
m_camTransform.eulerAngles = m_camRotateA
//// 原来的设计,也是正确的
//float rh = Input.GetAxis(&Mouse X&);
//float rv = Input.GetAxis(&Mouse Y&);
//m_camRotateAngles.x -=
//m_camRotateAngles.y +=
//m_camTransform.eulerAngles = m_camRotateA
// 主角旋转,Player不会绕Z轴旋转,也不会绕x轴旋转,只是会绕Y轴做左右旋转
Vector3 transformRot = m_camTransform.eulerA
transformRot.x = transformRot.z = 0;
m_transform.eulerAngles = transformR
public Vector3
eulerAngles;
Description
The rotation as Euler angles in degrees.
The x, y, and z angles represent a rotation z degrees around the z axis, x degrees around the x axis, and y degrees around the y axis (in that order).
Only use this variable to read and set the angles to absolute values. Don't increment them, as it will fail when the angle exceeds 360 degrees.Use Transform.Rotate instead.
using UnityE
using System.C
public class ExampleClass : MonoBehaviour {
public float yRotation = 5.0F;
void Update() {
yRotation += Input.GetAxis(&Horizontal&);
transform.eulerAngles = new Vector3(10, yRotation, 0);
void Example() {
print(transform.eulerAngles.x);
print(transform.eulerAngles.y);
print(transform.eulerAngles.z);
Do not set one of the eulerAngles axis separately (eg. eulerAngles.x = 10; ) since this will lead to drift and undesired rotations.When setting them to a new value set them all at once as shown above.Unity will convert the angles to and from the rotation
stored in Transform.rotation.
public static float
MoveTowardsAngle(float current,float
target,float maxDelta);
Parameters
Description
Same as MoveTowards but makes sure the values interpolate correctly when they wrap around 360 degrees.
Variables current and target are assumed to be in degrees.For optimization reasons, negative values of
maxDelta are not supported and may cause oscillation. To push
current away from a target angle, add 180 to that angle instead.
using UnityE
using System.C
public class ExampleClass : MonoBehaviour {
public float target = 270.0F;
public float speed = 45.0F;
void Update() {
float angle = Mathf.MoveTowardsAngle(transform.eulerAngles.y, target, speed * Time.deltaTime);
transform.eulerAngles = new Vector3(0, angle, 0);
本文已收录于以下专栏:
相关文章推荐
原文地址:http://blog.csdn.net/mysniper11/article/details/8766574
欧拉角是一种常用的描述方位的方法。这项技术是著名数学家Leo...
根据物体移动方向,求其面向此方向时的欧拉角Vector3
Vector3 eulerAngles = Quaternion.FromToRotation(Vector3.forwa...
这个QTcpServer
类提供了一个TCP基础连接
   这个类创建一个即将到来的tcp连接 调用listen去建立服务,当一个客户连接到达的时候,会发射newConnection()信...
在gemfield的《从pthread到QThread》一文中我们了解了线程的基本使用,但是有一大部分的内容当时说要放到这片文章里讨论,那就是线程的同步问题。关于这个问题,gemfield在《从进 程...
前一段时间通过调试Qt源码,大致了解了Qt的事件机制、信号槽机制。毕竟能力和时间有限。有些地方理解的并不是很清楚。
开发环境:linux((fedora 17),Qt版本(qt-everywhere-...
先普及一下什么是物体坐标,什么是惯性坐标,世界坐标:《3D数学基础图形与游戏开发》中第三章--&3.24节
物体坐标与惯性坐标的原点相同,物体坐标只需要旋转就可以变为惯性坐标,惯性坐...
哦也,公司年会开完就放假,年前不会再更新了~
提前恭祝大家新年快乐,心想事成~
public Transform target
public int moveSpeed
旋转,应该是三种坐标变换——缩放、旋转和平移,中最复杂的一种了。大家应该都听过,有一种旋转的表示方法叫四元数。按照我们的习惯,我们更加熟悉的是另外两种旋转的表示方法——矩阵旋转和欧拉旋转。矩阵旋转使用...
他的最新文章
讲师:刘文志
讲师:陈伟
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)欧拉角到底有什么用【unity3d吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:77,363贴子:
欧拉角到底有什么用收藏
这是第一人称自带的MousLock脚本: public class MouseLook : MonoBehaviour {public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }public RotationAxes axes = RotationAxes.MouseXAndY;public float sensitivityX = 15F;public float sensitivityY = 15F;public float minimumX = -360F;public float maximumX = 360F;public float minimumY = -60F;public float maximumY = 60F;
public float moveSensitivity = 1.0f;float rotationX = 0F;float rotationY = 0F;Quaternion originalRvoid Update (){
//if (Input.GetMouseButton(0))
if (axes == RotationAxes.MouseXAndY)
// Read the mouse input axis
rotationX += Input.GetAxis(&Mouse X&) * sensitivityX;
rotationY += Input.GetAxis(&Mouse Y&) * sensitivityY;//检查是是否越界
rotationX = ClampAngle(rotationX, minimumX, maximumX);
rotationY = ClampAngle(rotationY, minimumY, maximumY);
Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);
Quaternion yQuaternion = Quaternion.AngleAxis(rotationY, Vector3.left);
transform.localRotation = originalRotation * xQuaternion * yQ
else if (axes == RotationAxes.MouseX)
rotationX += Input.GetAxis(&Mouse X&) * sensitivityX;
rotationX = ClampAngle(rotationX, minimumX, maximumX);
Quaternion xQuaternion = Quaternion.AngleAxis(rotationX, Vector3.up);
transform.localRotation = originalRotation * xQ
rotationY += Input.GetAxis(&Mouse Y&) * sensitivityY;
rotationY = ClampAngle(rotationY, minimumY, maximumY);
Quaternion yQuaternion = Quaternion.AngleAxis(rotationY, Vector3.left);
transform.localRotation = originalRotation * yQ
}}void Start (){// Make the rigid body not change rotationif (rigidbody)rigidbody.freezeRotation =originalRotation = transform.localR}public static float ClampAngle (float angle, float min, float max){if (angle & -360F)angle += 360F;if (angle & 360F)angle -= 360F;return Mathf.Clamp (angle, min, max);}}请问自带的MouseLock和我下面的这段控制代码(没有用到欧拉角)有什么不同吗,他们不都是可以控制前、后、左、右移动,还有镜头的左右、上下移动吗?
来火星时代学习unity3d,强大美术资源,多年游戏教学实力,20000家合作企业,毕业=就业,火星时代unity3d,业界精英一对一辅导,参与游戏实训项目,工作经验不再是零.
lz写的代码没有旋转角度限制,只适合直升机控制器用,mouselook做了旋转角度限制适合fps控制器用
我运行了一下,你上面那段代码不能控制移动
登录百度帐号推荐应用计算机3D图形基础在Unity中的实现(Vector3,Maxtrix4*4,Transform)
&magnitude&&&&&&&&&&&&&&返回向量长度值(只读),这词取得真怪,反正就是向量的模运算,得到向量的长度。公式就是x平方+y平方+z平方然后根号便是。这都不记得了赶紧回家面壁。&sqrmagnitude&&&&&&&&&返回向量的平方长度(只读)。上面那个不开根号就是了。&方法:&Scale(a:vector3,b:vector3):vertor3&&缩放,返回a的每个坐标乘以b的相对应的每个坐标。注意他是静态函数。&Normalize()&向量化,注意magnitude向量长度会变为1.&类特有的一些属性(直接粘help的了):&zero&&&&&&Shorthand for writing Vector3(0, 0, 0)&one&&&&&& Shorthand for writing Vector3(1, 1, 1)&forward&& Shorthand for writing Vector3(0, 0, 1)&up&&&&&&&&Shorthand for writing Vector3(0, 1, 0)&right&&&& Shorthand for writing Vector3(1, 0, 0)&Maxtrix4*4:&矩阵也是3D图形学一个重要的概念,在D3D里用的很平凡,但是U3D里好像都已经封装到各个Object上去了,所以很容易忽视掉,但不能忽视它的存在。在3D世界里,每个物体均有自身的世界矩阵,摄像机有摄像机矩阵,投影场景有projection矩阵,对顶点、向量、物体实施各种平移、旋转、缩放都是通过矩阵来完成的。计算机3D物体的标准4×4矩阵是这样定义的:(表示不出来矩阵大括号,请读者就当左4行的[和右4行的]当成一对大括号)&&&&&&&&&&&&&&&&&&&[ x,&&y&&,z&&,0]&&&&&-&&物体的右方向向量&&&&&&&&&&&&&&&&&&&[ x,&&y&&,z&&,0]&&&&&-&&物体的上方向向量&&&&&&&&&&&&&&&&&&&[ x,&&y&&,z&&,0]&&&&&-&&物体的前方向向量&&&&&&&&&&&&&&&&&&&[ x,&&y&&,z&&,1]&&&&&-&&物体所在的坐标&注意:前三行的坐标一定是互有90度的,(除非特殊情况,例如空间扭曲之类的=.=)因为他们是物体的三个坐标轴。第四列的 0 0 0 1 是为了补齐4*4矩阵,为了计算方便而已。&矩阵一样有单位矩阵和0矩阵,&[1 0 0]&[0 1 0]&& 其他的我就不说了,在Unity里头是完全封装的(见Transform)&[0 0 1]&Transform:&这个就是U3D所封装的矩阵运算了,用于缩放,平移,还有定位(这个囧,他把矩阵给放这用了,所有物体都可以用transform类型来存放)。Transform所实现的功能不过就是物体矩阵的运算罢了,具体如下:&Variables&position&&&&&&&&&&&&&&&&&&&&Vector3类型,物体位置,相对于世界坐标系的值。就是矩阵的最后一行的值。&localPosition&&&&&&&&&&&& Vector3类型,物体相对于父元素的位置.&eulerAngles&&&&&&&&&&&&&&Vector3类型,旋转后的欧拉角相对世界坐标的值。简单理解为各向量坐标所转动的值就好了。&localEulerAngles&&&&&&Vector3类型,相对父元素的欧拉角。&right&&&&&&&&&&&&&&&&&&&&&&&&Vector3类型,表示x轴(U3里红色的轴)方向的单位向量。&up&&&&&&&&&&&&&&&&&&&&&&&&&& Vector3类型,表示y轴(U3里绿色的轴)方向的单位向量。&forward&&&&&&&&&&&&&&&&&& Vector3类型,表示z轴(U3里蓝色的轴)方向的单位向量。&rotation&&&&&&&&&&&&&&&&&& Quaternion类型(quatermion就是个四维数,比vector3多一个w变量表示旋转角度的),世界坐标旋转。.&localRotation&&&&&&&&&&&Quaternion类型,本地坐标的旋转度数(相对父元素)。&localScale&&&&&&&&&&&&&&&&Vector3类型,相对本地坐标系缩放(就是矩阵的乘法)&parent&&&&&&&&&&&&&&&&&&&&&&Transform类型,他的父元素。&worldToLocalMatrix&&Matrix4*4类型,把一个点从世界坐标系的位置转换为本地坐标系位置。(终究得用矩阵,哈哈)只读&localToWorldMatrix&&Matrix4*4类型,把一个点从本地坐标系转换为世界坐标系。(只读)&root&&&&&&&&&&&&&&&&&&&&&&&&&&Transform类型,返回最上层的那个Transform,就是他父亲的父亲的父亲的。。。(如果有的话)&childCount&&&&&&&&&&&&&&&&int型,你子元素的数量。。。&lossyScale&&&&&&&&&&&&&&&&Vector3类型,相对世界坐标系缩放。&Functions&Translate (translation : Vector3, relativeTo : Space=Space.Self) : void&& 平移物体,space可以是Self和World,这个不用说了吧&Rotate (eulerAngles : Vector3, relativeTo : Space = Space.Self) : void&&绕欧拉角度的向量旋转&RotateAround (point : Vector3, axis :Vector3, angle : float) : void&&点point按axis的轴旋转angle度&LookAt (target : Transform, worldUp :Vector3 ) : void&让这个物体的z轴面向target物体&TransformDirection (direction : Vector3) : Vector3&&将direction从本地坐标转换为世界坐标&InverseTransformDirection (direction : Vector3): Vector3&&将derection从世界坐标转换为本地坐标&TransformPoint (position :Vector3): Vector3&&同理&InverseTransformPoint (position : Vector3) : Vector3&DetachChildren () : void&&&&解除所有子对象&Find (name : string) : Transform&& 按名字寻找并返回子对象&IsChildOf (parent : Transform) : bool&& 看他是不是别人的子对象&
看过本文的人也看了:
我要留言技术领域:
取消收藏确定要取消收藏吗?
删除图谱提示你保存在该图谱下的知识内容也会被删除,建议你先将内容移到其他图谱中。你确定要删除知识图谱及其内容吗?
删除节点提示无法删除该知识节点,因该节点下仍保存有相关知识内容!
删除节点提示你确定要删除该知识节点吗?2462人阅读
Unity(38)
根据物体移动方向,求其面向此方向时的欧拉角
Vector3 velocity
Vector3 eulerAngles = Quaternion.FromToRotation(Vector3.forward, velocity).eulerAngles
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:28476次
排名:千里之外
原创:32篇
转载:15篇
(1)(1)(1)(3)(1)(5)(2)(5)(3)(1)(1)(6)(7)(10)(1)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'

我要回帖

更多关于 transform rotate3d 的文章

 

随机推荐