纳金网

标题: 如何写飞行(就是能够前后左右 上下移动相机) [打印本页]

作者: 她。    时间: 2013-1-30 09:03
标题: 如何写飞行(就是能够前后左右 上下移动相机)
请问如何上下左右前后移动相机并且让他停在移动后的位置上。我能够上下左右前后移动相机 但是一旦放开向上移动键后由于重力作用 相机就会下掉。我给他加了一个力也不行不知道怎么回事求大神解答。         if (grounded)        {            if (!(Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))) //如果没有按下左Ctrl键            {              if(!(Input.GetKey(KeyCode.Space))){                //只能前后平移                  moveDirection = new Vector3(0, 0, Input.GetAxis("Vertical"));                moveDirection = transform.TransformDirection(moveDirection);                moveDirection *= speed;}else{//只能前后上下平移                  moveDirection = new Vector3(0, Input.GetAxis("Vertical"), Input.GetAxis("Vertical"));                moveDirection = transform.TransformDirection(moveDirection);                moveDirection *= speed;}            }            else //            {                ///可前后左右平移                moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));                moveDirection = transform.TransformDirection(moveDirection);                moveDirection *= speed;            }/*             if (Input.GetButton("Jump")) //跳跃            {                moveDirection.y = jumpSpeed;             }*/        }         //重力        moveDirection.y -= gravity * Time.deltaTime;if(Input.GetButton("Jump")){moveDirection.y += gravity * Time.deltaTime;}else{//我在这里给他加了一个向上的等于重力的力。rigidbody.AddForce (0, (rigidbody.mass+20)*(gravity+5), 0);}  




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