[Unity菜鸟] Character控制移动
2014-06-30 15:53
316 查看
1. 给角色加角色控制器组件,然后用以下代码可以控制角色移动和跳跃
2. 添加角色控制器后人物下陷问题
float speed = 6.0f; float jumpSpeed = 8.0f; float gravity = 20.0f; private Vector3 moveDirection = Vector3.zero; void Start() { // gameObject.rigidbody = false; } void Update() { CharacterController controller = GetComponent<CharacterController>(); if(controller.isGrounded) { moveDirection =new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); //Allows for player input moveDirection = transform.TransformDirection(moveDirection); //How to move moveDirection *= speed; //How fast to move if(Input.GetButton("Jump")) { moveDirection.y = jumpSpeed; } } //Apply gravity moveDirection.y -= gravity * Time.deltaTime; //Move the controller controller.Move(moveDirection * Time.deltaTime); }
2. 添加角色控制器后人物下陷问题
相关文章推荐
- Unity 移动端简单手势控制(移动,旋转,缩放)
- unity键盘控制人物移动
- Unity控制移动、旋转
- unity之手机端摇杆控制人物移动
- Unity中使用鼠标控制相机的视口方向以及移动
- Unity3D学习之 ------------------------ "Hello Unity"控制角色移动
- unity 手指移动物体旋转两个手指控制物体大小缩放
- 我的Unity(10)一点一滴 利用UI制作摇杆控制物体移动
- Unity 里禁用HTCVIVE跟随玩家移动(只控制旋转)
- unity 通过键盘控制角色的移动和旋转
- unity中简单的角色移动控制
- Unity中鼠标点击地面控制人物移动
- Unity 3D 控制物体上下左右均匀移动脚本
- unity之按键控制移动,及按键之后,走动动画才能播放(正常行走)
- Unity摇杆控制物体移动c#脚本
- Unity键盘控制物体移动
- 通过滑动手势控制摇杆移动并且通过移动的速度控制能量条的增长 Unity
- Unity2D - 2. 实现基本的人物移动控制和碰撞检测
- Unity控制鼠标移动及点击
- unity 点击按钮控制物体移动