纳金网

标题: unity3d第三人称角色控制教程-4(下) [打印本页]

作者: 会飞的鱼    时间: 2011-12-9 15:00
标题: unity3d第三人称角色控制教程-4(下)
Code Paste

In case you got lost or something doesnt work, here is a paste of the entire controller script:
private var walkSpeed : float = 1.0;

private var gravity = 100.0;

private var moveDirection : Vector3 = Vector3.zero;

private var charController : CharacterController;
function Start()

{

    charController = GetComponent(CharacterController);

    animation.wrapMode = WrapMode.Loop;

}
function Update ()

{

    if(charController.isGrounded == true)

    {

        if(Input.GetAxis("Vertical") > .1)

        {

            if(Input.GetButton("Run"))

            {

                animation.CrossFade("run");

                walkSpeed = 4;

            }

            else

            {

                animation["walk"].speed = 1;

                animation.CrossFade("walk");

                walkSpeed = 1;

            }

        }

        else if(Input.GetAxis("Vertical") < -.1)

        {

            animation["walk"].speed = -1;

            animation.CrossFade("walk");

            walkSpeed = 1;

        }

        else

        {

            animation.CrossFade("idle");

        }
        // Create an animation cycle for when the character is turning on the spot

        if(Input.GetAxis("Horizontal") && !Input.GetAxis("Vertical"))

        {

            animation.CrossFade("walk");

        }
        transform.eulerAngles.y += Input.GetAxis("Horizontal");
        // Calculate the movement direction (forward motion)

        moveDirection = Vector3(0,0, Input.GetAxis("Vertical"));

        moveDirection = transform.TransformDirection(moveDirection);
    }
    moveDirection.y -= gravity * Time.deltaTime;

    charController.Move(moveDirection * (Time.deltaTime * walkSpeed));

}





由 u8  发表




作者: tc    时间: 2012-2-11 23:33
我看看就走,你们聊!

作者: C.R.CAN    时间: 2012-4-3 23:19
“再次路过……”我造一个-----特别路过

作者: 晃晃    时间: 2012-4-11 23:31
都闪开,介个帖子,偶来顶

作者: markq    时间: 2012-4-12 22:48
不错 非常经典 实用
作者: 晃晃    时间: 2012-5-4 23:27
凡系斑竹滴话要听;凡系朋友滴帖要顶

作者: 菜刀吻电线    时间: 2012-6-15 23:25
很经典,很实用,学习了!

作者: 晃晃    时间: 2012-6-18 23:19
有意思!学习了!

作者: C.R.CAN    时间: 2012-7-7 23:19
百度的叫度娘,网易的叫易娘,新浪内部还在为是叫新娘还是浪娘而争论不休!……不管你们是企鹅的额娘,豆瓣的伴娘,还是华为的伪娘,都要记得,淘宝才是你们的亲娘啊!亲!!

作者: 奇    时间: 2012-7-21 23:26
呵呵,很好,方便罗。

作者: 奇    时间: 2012-8-15 01:04
不错哦,顶一下......

作者: C.R.CAN    时间: 2013-2-1 23:22
俺是新人,这厢有礼了!

作者: tc    时间: 2013-2-18 23:24
路过、路过、快到鸟,列位请继续...ing

作者: 晃晃    时间: 2013-3-6 23:21
我是老实人,我来也!





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5