Mathf
- Abs
- Acos
- Approximately
- Asin
- Atan2
- Atan
- CeilToInt
- Ceil
- Clamp01
- Clamp
- ClosestPowerOfTwo
- Cos
- Deg2Rad
- DeltaAngle
- Epsilon
- Exp
- FloorToInt
- Floor
- Infinity
- InverseLerp
- IsPowerOfTwo
- LerpAngle
- Lerp
- Log10
- Log
- Max
- Min
- MoveTowardsAngle
- MoveTowards
- NegativeInfinity
- NextPowerOfTwo
- PingPong
- PI
- Pow
- Rad2Deg
- Repeat
- RoundToInt
- Round
- Sign
- Sin
- SmoothDampAngle
- SmoothDamp
- SmoothStep
- Sqrt
- Tan
Mathf.Atan2 反正切2
static function Atan2 (y : float, x : float) : float
Description描述
Returns the angle in radians whose Tan is y/x.
以弧度为单位计算并返回 y/x 的反正切值。返回值表示相对直角三角形对角的角,其中 x 是临边边长,而 y 是对边边长。
Return value is the angle between the x-axis and a 2D vector starting at zero and terminating at (x,y).
返回值是在x轴和一个二维向量开始于0个结束在(x,y)处之间的角。
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public Transform target;
void Update() {
Vector3 relative = transform.InverseTransformPoint(target.position);
float angle = Mathf.Atan2(relative.x, relative.z) * Mathf.Rad2Deg;
transform.Rotate(0, angle, 0);
}
}
// Usually you use transform.LookAt for this.
//通常使用transform.lookAt.
// But this can give you more control over the angle
//但这可以给你更多的对角度的控制
var target : Transform;
function Update () {
var relative : Vector3 = transform.InverseTransformPoint(target.position);
var angle : float = Mathf.Atan2(relative.x, relative.z) * Mathf.Rad2Deg;
transform.Rotate (0, angle, 0);
}
最后修改:2011年2月21日 Monday 12:32