玩家输入–通过转化为数字信号的方式进行输入:
设置键位和0~1之间进行平滑过渡
人物移动的数字信号转化:
public string keyUp = "w";
public string keyDown="s";
public string keyLeft="a";
public string keyRight="d";
//通过三元运算符判定是否有按下这些键,从而进行赋值水平和垂直方向是 1或者-1
targetDup = (Input.GetKey(keyUp) ? 1.0f : 0) - (Input.GetKey(keyDown) ? 1.0f : 0);
targetDright = (Input.GetKey(keyRight) ? 1.0f : 0) - (Input.GetKey(keyLeft) ? 1.0f : 0);
//当没有按时就需要把玩家停下来
if (inputEnabled==false) {
targetDup = 0;
targetDright = 0;
}
//通过Mathf.SmoothDamp让Dup逐渐趋向与目标
Dup = Mathf.SmoothDamp(Dup, targetDup, ref velocityDup, 0.1f);
Dright = Mathf.SmoothDamp(Dright, targetDright, ref velocityDright, 0.1f);
人物转向:
通过输入数字信号的长度计算玩家当前的方向
//解决斜着的速度比水平垂直的速度快
private Vector2 SquareToCircle(Vector2 input) {
Vector2 output = Vector2.zero;
output.x <

最低0.47元/天 解锁文章
2982

被折叠的 条评论
为什么被折叠?



