Lirb 的头像

Lirb.

Unity Gameplaying
P1 / 游戏策划

“我们的旅程是星辰大海”

“一个简单普通的男孩”

站点信息

文章数目: 8 篇

最近动态: 2月前

上线时间: 1690天

当前版本: v1.0.2

READ / JOURNAL▪

【更高级的运动系统】关于在Unity中如何处理角色急停

引言

最近在尝试制作二次元ACT游戏,在处理角色急停动画时研究下如何使动画更加自然,流畅;能根据移动状态下角色脚步来判断急停时所使用的动画。

动画

首先,需要两个动画,一个是左脚急停,一个是右脚急停。

如何判断

其实原理很简单,我只要在我松开移动键的时候判断左右脚的相对位置即可决定急停的动画;要是移动最后一帧是左脚在前,那角色急停结束后就会是右脚在前。

当然,判断相对位置需要找到一个合适的相对坐标,在这里,我用模型的Hip位置来当作坐标原点。

当移动动画最后一帧右脚在前时,播放的急停动画则会是左脚向前。

当移动动画最后一帧左脚在前时,播放的急停动画则会是右脚在前

这样,角色的移动和停顿就会更加自然。

判断代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//用于创建相对坐标 
private Vector3 GetRelativePosition(Transform hip, Transform foot)
{
Vector3 distance = foot.position - hip.position;
Vector3 relativePosition = Vector3.zero;
relativePosition.x = Vector3.Dot(distance, hip.right.normalized);
relativePosition.y = Vector3.Dot(distance, hip.up.normalized);
relativePosition.z = Vector3.Dot(distance, hip.forward.normalized);
return relativePosition;
}
//判断左右脚坐标
public bool GetFootPosition()
{
Vector3 leftPos = GetRelativePosition(hip, leftFoot);
Vector3 rightPos = GetRelativePosition(hip, rightFoot);
if(leftPos.z > 0 && rightPos.z < 0)
{
return true;
}
return false;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
switch (moveState)
{
case MoveChildState.Move:
player.PlayerAnimation("Move");
break;
case MoveChildState.RunStop:
if (player.GetFootPosition())
{
pos = "L";
}
else
{
pos = "R";
}
player.PlayerAnimation("RunStop_"+pos);
break;
}

评论区

欢迎你留下宝贵的意见,昵称输入QQ号会显示QQ头像哦~

更新记录

CHANGELOG

22 条更新 2026 年

少多
活跃 12 天最近 2026-10-02

点击亮色方块查看当天更新

查看本年日志
  • 网站改版

    新增独立更新日志与年份切换

  • 历史部署

    历史部署:feat(site): publish pixel theme and interactive toolbox

  • 历史部署

    历史部署:Site updated: 2026-08-14 21:58:40

  • 历史部署

    历史部署:Site updated: 2026-08-14 21:49:25

  • 历史部署

    历史部署:Site updated: 2026-08-14 15:46:44

  • 历史部署

    历史部署:Site updated: 2026-08-14 15:23:26

  • 历史部署

    历史部署:Site updated: 2026-08-14 14:56:59

  • 文章发布

    让Boss与玩家真正“打起来”——《漫威蜘蛛侠2》Boss战设计分析

  • 历史部署

    历史部署:Site updated: 2026-07-29 18:34:53

  • 历史部署

    历史部署:Site updated: 2026-07-27 09:06:17

  • 历史部署

    历史部署:Merge main branch for Pages deployment

  • 历史部署

    历史部署:Site updated: 2026-07-26 15:11:12

  • 历史部署

    历史部署:Site updated: 2026-07-26 15:44:10

  • 历史部署

    历史部署:Site updated: 2026-07-04 10:02:55

  • 历史部署

    历史部署:Site updated: 2026-05-17 10:31:06

  • 历史部署

    历史部署:Site updated: 2026-05-14 09:52:35

  • 历史部署

    历史部署:Site updated: 2026-05-14 09:47:30

  • 历史部署

    历史部署:Site updated: 2026-05-13 11:10:05

  • 历史部署

    历史部署:Site updated: 2026-05-12 10:31:20

  • 历史部署

    历史部署:Site updated: 2026-05-12 10:53:10

  • 历史部署

    历史部署:Site updated: 2026-05-06 theme redesign

  • 历史部署

    历史部署:Site updated: 2026-05-06 11:31:01

构建时记录变化,上传后更新。文章同日修改、网站同日改版各合并计次;历史部署单独标注。

Built with Hexo

Lirb. / PIXEL JOURNAL