Transform Learning and Application _unity3d

Source: Internet
Author: User

Link:http://blog.sina.com.cn/s/blog_4a2183a60100niet.html

Transform transform, is the most common class in the scene, used to control the object's displacement, rotation, scaling and other functions. Transform Class, inherits from Component, IEnumerable Position, rotation and scale of the An object. Controls the position, rotation, and scaling of the object. Every object in a scene has a Transform. It ' s used to store and manipulate the position, rotation and scale of the object. Every Transform can have a parent, which allows to apply position, rotation and scale hierachically. This is the hierarchy seen in the hierarchy pane. They also support enumerators so-can loop through children using://Moves all Transform children units
for (Var child:transform in Transform) {
Child.position + = vector3.up * 10.0;
}
Each object in the scene has transform this class, which is used to store and handle the displacement, rotation and scaling of the object. Each transform can have a parent object, which allows you to get the displacement rotation and scaling of the downstream node. This hierarchical relationship can be seen from the hierarchy panel. He also supports enumerators to use loops to find all the child nodes. Variables
The position of the Position:vector3 object in world coordinates. Transform.position=vector3 (10,10,10)//Place the object in (x=10,y=10,z=10)
Localposition:vector3 relative position, or position, relative to the position of the parent object.
Eulerangles:vector3 axial rotation angle, relative to world coordinates. Unit for degrees (°)
Localposition:vector3 the rotation of the object relative to the parent object, relative to the axial rotation angle, or its own rotational angle. This value is used for general use and handling of the rotation angle of an object.
Right:vector3 the position of the red axis (x axis) of the object itself in world coordinates. Notice that in Maya the X axis points to the left side of the object, and the X axis in Unity points to the right side of the object. rigidbody.velotity=transform.right*movespeed;//to the right of the object at a movespeed speed.
Up:vector3 the position of the green axis (Y-axis) of the object itself in world coordinates.
Forward:vector3 the blue axis (z-axis) of the object itself to the position in world coordinates.
Rotation:quaternion the rotation of the object itself, expressed as a four-dollar number. A four-dollar number can be used to quickly calculate the direction of rotation of an object, with a quaternion that can be applied to calculate the various needs of the rotation scheme. Specific application methods see quaternion article
Localrotation:quaternion a rotation that is expressed as a four-dollar number relative to the parent object.
The scaling of a Localscale:vector3 object relative to the parent object
The parent object of a Parent:transform object. Returns null if it is not. If you change the position of the parent object, rotate and zoom, it will affect and change the position of the child object, rotate and zoom, but keep the relative position, relative rotation and relative scaling.
worldtolocalmatrix:matrix4x4 a four-dimensional matrix that expresses the position from world coordinates to relative coordinates, Read only. If you are not very familiar with the matrix, please use Transform.inversetransformpoint.
localtoworldmatrix:matrix4x4 a four-dimensional matrix that expresses its position from relative coordinates to world coordinates, Read only. If you are not very familiar with the matrix, please use Transform.transformpoint.
Root:transform returns the parent object at the highest level of the object. If the object itself is the highest level, return the object itself.
Childcount:int returns the number of child objects of an object.
Lossyscale:vector3 returns the scale value of the object relative to world coordinates. Read only. No use of a property, when the child objects are rotated is not particularly accurate, also do not recommend everyone to use. If you want to calculate the world coordinate scaling of an object, it's best to write the formula yourself.

Functions 1) Translate, a function used to move objects, a function that is commonly used. function Translate (Translation:vector3, relativeto:space = space.self): Void moves the object to the translation direction, the distance is Translation.magn Itude. RelativeTo represents the reference coordinate system for this movement. function Translate (x:float, Y:float, z:float, relativeto:space = space.self): Void ditto function Translate (transl Ation:vector3, relativeto:transform): void if relativeto is not NULL, the target object relativeto its own axis as a reference coordinate system. function Translate (x:float, Y:float, Z:float, relativeto:transform): void ditto
Script: Var speed=30;
Move the object forward at a rate of 30 meters per second. Trasform. Translate (Vector3.forward*speed*time.deltatime);

2 Rotate, the function used to rotate the object is very commonly used, in the case of knowing the angle of rotation needed. If you want to rotate the object to a specified position, you need to use it with quaternion. function Rotate (Eulerangles:vector3, relativeto:space = space.self): Void rotation eulerangles degree (3 axes are rotated separately), relativeto as reference coordinate system function Rotate (xangle:float, Yangle:float, zangle:float, relativeto:space = space.self): Void ditto function Rota Te (Axis:vector3, angle:float, relativeto:space = space.self): Void rotates angle degrees axis, with RelativeTo as reference coordinate system
3 Rotatearound let the object to a certain point as the axis of a circular motion. function Rotatearound (Point:vector3, Axis:vector3, angle:float): Void allows the object to be point-centric and axis-rotating angle degrees around axis. Keep the original distance from point.
4) LookAt Let the object's z-axis look toward the target object function LookAt (target:transform, Worldup:vector3 = vector3.up): void allows the z axis of the object to look at the target position and worl The DUP is the Y axis pointing direction. function LookAt (Worldposition:vector3, Worldup:vector3 = vector3.up): Void lets object look toward Worldposition 5) transformdirection F Unction transformdirection (DIRECTION:VECTOR3): Vector3 returns the vector direction in world coordinates that is the axis of the object itself. function Transformdirection (x:float, Y:float, z:float): Vector3 ditto 6) inversetransformdirection function Inversetra Nsformdirection (DIRECTION:VECTOR3): Vector3 function Inversetransformdirection (x:float, Y:float, z:float): Vec Tor3, instead of transformdirection, converts from world coordinates to its own relative coordinates.
7) Transformpoint function Transformpoint (POSITION:VECTOR3): Vector3 function Transformpoint (x:float, y:float, Z: FLOAT): Vector3 Converts a point from its own relative coordinates to world coordinates 8 inversetransformpoint function Inversetransformpoint (POSITION:VECTOR3): Vector3 function Inversetransformpoint (x:float, Y:float, z:float): Vector3 Converts a point from the time coordinate to the location of its own coordinates. 9) Detachchildren function Detachchildren (): void sets the parent object of all its own objects into the world, which is to contact the parent-child relationship with all of its own objects.
Finding function Find (name:string): Transform finds an object named name and returns NULL if it is not found. If the string is/isolated, the function is checked up and down like a file path.
The magical rotating finger
function Update () {
Afinger = transform. Find ("Leftshoulder/arm/hand/finger");
Afinger.rotate (time.deltatime*20, 0, 0);
}
Ischildof function Ischildof (parent:transform): BOOL Returns True if the object is a member of parent's parent-child hierarchy relationship;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.