纳金网
标题:
U3D如何让物体旋转一定角度
[打印本页]
作者:
比巴卜
时间:
2012-10-8 14:04
标题:
U3D如何让物体旋转一定角度
U3D如何让物体旋转一定角度
作者:
艾西格亚
时间:
2012-10-8 22:50
以相机为例,写入以下代码:
public var cm:Camera;//Camera Object
public var maxRotationAngle = 20;//Max Rotation Angle each side
private var currentAngle = .0;
function Update ()
{
var cfAngle = 15 * Time.deltaTime;
if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
cfAngle = -cfAngle;
}
else if(Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
}
else
{
return;
}
var newcurrentAngle = currentAngle + cfAngle;
if(newcurrentAngle > maxRotationAngle) newcurrentAngle = maxRotationAngle;
if(newcurrentAngle < -maxRotationAngle) newcurrentAngle = -maxRotationAngle;
cfAngle = newcurrentAngle - currentAngle;
currentAngle = newcurrentAngle;
cm.transform.Rotate(cm.transform.InverseTransformDirection(Vector3.up) * cfAngle);
}
作者:
其实我是神
时间:
2012-10-9 08:50
作者:
比巴卜
时间:
2012-10-9 09:29
欢迎光临 纳金网 (http://go.narkii.com/club/)
Powered by Discuz! X2.5