查看: 5032|回复: 0
打印 上一主题 下一主题

U3D如何让物体旋转一定角度

[复制链接]

955

主题

164

听众

7万

积分

版主

Rank: 7Rank: 7Rank: 7

纳金币
59338
精华
28

活跃会员 荣誉管理 突出贡献 优秀版主 论坛元老

楼主
发表于 2012-10-8 22:50:49 |显示全部楼层
以相机为例,写入以下代码:



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);

   

}


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-21 18:53 , Processed in 0.080070 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部