UNITY2D Game Development Study notes, Euler angle, four yuan, universal joint, LERP,MATHF

Source: Internet
Author: User

*mathf

Unity MATHF Math Operations (C #)

*Vector3. Lerp

The second line uses to determine the zombie's new location along the path between it current and Vector3.Lerp target locations. is Lerp a convenient method that interpolates between the values based on a third value. Lerp Clamps the third value between zero and one and interprets it as a fraction along the path between the both points. That means a value of 0 would return currentPosition , a value 1 of would return target , and a value of 0.5 would return the Midpoint between them.

Vector3.lerp interpolation

static function Lerp (From:vector3, To:vector3, t:float): Vector3

Description Description

Linearly interpolates between, vectors.

The linear interpolation between the two vectors.

Interpolates from towards to by Amount T.

Interpolates between from and to by the number T.

T is clamped between [0...1]. When t = 0 returns from. When t = 1 returns to. When t = 0.5 returns the average of from and to.

T is sandwiched between [0...1], when t = 0 o'clock, returns from, when t = 1 o'clock, returns to. When t = 0.5 returns the average of the From and to.

    • 0c#
    • Javascript
// Animates the position to move from start to end within one second//在1秒时间动画位置移动从from开始到to结束。var start : Transform;var end : Transform;function Update () {transform.position = Vector3.Lerp(start.position, end.position, Time.time);}

Another example:

    • C#
    • Javascript
// Follows the target position like with a spring//像弹簧一样跟随目标物体var target : Transform;var smooth = 5.0;function Update () {transform.position = Vector3.Lerp (transform.position, target.position,Time.deltaTime * smooth);}

 

//---------------------------

You'll use the turnSpeed your calculations to control how quickly the zombie reorients himself to a new direction.

Unity uses quaternions internally to represent rotations. If you ' re curious about the details of the math, check outthis info. Then after you've cleaned up the mess from your head exploding and take solace in the fact so you really don ' t need to kno W anything about quaternions when working with 2D.

That's because the Quaternion.Euler method lets you create a object from an Quaternion Euler angle. Euler Angles is the ones most people is accustomed to, consisting of individual x, Y and z rotations. While they aren ' t ideal for 3D work because of problems like gimbal lock, Euler angles is just fine for 2D games where yo U probably only want to rotate around the z-axis.

//---------------------------

Quaternion of four Yuan.

So the use of four yuan

Four-element Advantage
Very easy to Difference value (interpolate)
Completely eliminate gimbal Lock (or no singularity)
Although the four element is eventually reverted to a matrix, the four element is much more efficient than the matrix at the time of the multiplication.

http://blog.csdn.net/wangxiaojun911/article/details/4644243

Detailed description of the http://www.cnblogs.com/softimagewht/archive/2010/11/16/1878331.html inside the Untiy3d

//---------------------------

Gimbal Lock

Questions about the Universal Joint deadlock (Gimbal Lock) http://game.ceeger.com/Unity/Doc/2011/Gimbal_Lock.html

You can look for YouTube videos.

The universal joint of Euler's angle is a deadlock: We rotate the x-axis, y-axis, and z-axis of the object's coordinate system in turn, and when the y-axis rotates 90 degrees, Z points to the original x-axis. This way, we actually rotate only around the x-axis and the y-axis two axes, and the freedom of the third axis is lost! (It is worth pointing out that we use the X, Y, z axes of the world coordinate system when we describe it, but when it is rotated, it is used around the object.)

UNITY2D Game Development Study notes, Euler angle, four yuan, universal joint, LERP,MATHF

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.