Gameojbct 和Transform

rotate 自转  放在父类下可实现绕点转
rotatearound 围绕点转
lookat 自转 看着物体

Quaternion 看unity书
LookRotation 
Slerp


        transform Find (name)只能找子物体,不能找子子物体
        transform Find (name/name/name)能找子子物体

         GameObject.Find  可以找所有
         GameObject.FindGameObjectsWithTag 可以找所有
         GetComponentsInChildren 可以找所有子,再取gameobject


            mountGo.transform.localPosition += Vector3.up * 10 * Time.deltaTime;
            mountGo.transform.localPosition = new Vector3(mountGo.transform.localPosition.x, 10 * Time.deltaTime + transform.localPosition.y, mountGo.transform.localPosition.z);
            mountGo.transform.Translate(0, Time.deltaTime * 10, 0);


============================================

与高中数学颠倒
x为右,y为上,z为前

  • Shorthand for writing  Vector3(0, 0, 1)
    Vector3(0, 0, 1)的简码,也就是向z轴。
  • up
    Shorthand for writing  Vector3(0, 1, 0)
    Vector3(0, 1, 0)的简码,也就是向y轴。
  • Shorthand for writing  Vector3(1, 0, 0)
    Vector3(1, 0, 0)的简码,也就是向x轴。
 


此显示为局部坐标,x,y,z的移动是以父类的rotation大小为基轴
当没有父类的时候,以世界基轴为坐标,局部坐标就是世界坐标,
即 旋转自身坐标对自身不生效,对子类生效
======



此处显示的是旋转角度,对移动自己的local x,y,z 是依然以父类为基轴,子类才能生效
=====


transform.forward 蓝色向量,在世界坐标的表示,即以世界坐标的roatation为基轴表示


比如说有一个X物体,你要获取相对于它的前方矢量就是 
var x_direction :Vector3 = X.transform.TransformDirection(Vector.forward);
获取以X物体为轴  vector的前方  在世界坐标的向量 

即使旋转了45度但是当执行
transform.localPosition = Vector3.forward; 
物体依然会以父类。即世界坐标的方向移动
 

========
此时如果像以物体本身的y轴移动即
transform.localPosition = transform.TransformDirection(Vector3.forward);
计算出以 transform 物体为轴的  前方向  在世界坐标 的  方向,然后直接赋值
此时计算出的坐标是以 世界坐标为方向,与物体  本身x y z移动的方向的 坐标 是一致

等价于transform.forward
 
 ======
总结:
transform.TransformDirection(Vector3.forward)
当前物体的面向方向 vector.forward  在世界坐标的表示,即物体蓝色向量的世界坐标,
而不是以其父类世界坐标的vector。forward,虽然物体的移动是以父类的坐标移动
===
transform.InverseTransformDirection(Vector3.forward)
世界坐标forward 转化为当前坐标轴,即以transform为坐标轴的 局部变量。即使transform本身已经旋转了一定角度 
,此数值应该赋值给transform的子类,除非transform本身没有转向

猜你喜欢

转载自blog.csdn.net/a133900029/article/details/80184436
今日推荐