关于Unity中摇杆的操作

之前在解决摇杆控制角色的时候使用的是RPG游戏中主角的运动方式,有八个方向,最近找到一个新的方法,可以比较流畅地控制角色各个方向的移动

步骤

1.Easy Touch插件,角色控制器组件

 

2.在控制角色运动的脚本的Update方法中

float x = this.joystick.JoystickTouch.x;//摇杆坐标系的X坐标
float y = this.joystick.JoystickTouch.y;//摇杆坐标系的Y坐标
if (y != 0 || x != 0)
{
   //设置角色的朝向(朝向当前坐标+摇杆偏移量)  
   transform.LookAt(new Vector3(transform.position.x + x, transform.position.y, transform.position.z + y));
//移动玩家的位置(按朝向位置移动) this.c_ctrl.Move(transform.forward * Time.deltaTime * 4); //transform.Translate(Vector3.forward * Time.deltaTime * 4); //播放奔跑动画 this.anim.CrossFade("Run with carbine aimed", 0.2f); }

 

posted @ 2017-10-02 20:24  杭者  阅读(2459)  评论(0编辑  收藏  举报