- 最后登录
- 2017-5-15
- 注册时间
- 2012-3-1
- 阅读权限
- 90
- 积分
- 32973
  
- 纳金币
- 32806
- 精华
- 12
|
请问如何上下左右前后移动相机并且让他停在移动后的位置上。我能够上下左右前后移动相机 但是一旦放开向上移动键后由于重力作用 相机就会下掉。我给他加了一个力也不行不知道怎么回事求大神解答。 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);} |
|