我正在尝试重新创建一个移动系统以在我的游戏中使用。它来自一款名为 勇者斗恶龙英雄火箭史莱姆 的 DS 游戏,玩家可以做的其中一件事就是按住 A 键并朝一个方向移动以拉伸(stretch)他们的史莱姆。放开 A while stretched 会将它们的粘液朝它们拉伸(stretch)的方向甩掉。
这是一个显示关闭的 gif:
我有一堆玩家的状态枚举(行走、闲置、拉伸(stretch)、爆破(拉伸(stretch)后))。当玩家拉伸(stretch)时(在空闲时按住空格键),他们会在输入的方向上旋转,但我不确定我将如何在那个方向上缩放对象。
我的玩家 Sprite 嵌套在一个空的游戏对象中,以便我可以从一侧对其进行缩放(通过偏移玩家和缩放游戏对象)。我将播放器朝输入方向旋转,但我不完全确定如何按照示例 gif 中的方向将它们向前缩放。
if (curState == state.stretching)
{
rBody.velocity = new Vector2(0,0); //so we don't keep our momentum if we try to stretch while walking
transform.rotation = Quaternion.LookRotation(playerBody.transform.up, input);
transform.localScale = ///??
if (input.magnitude > 0)
{
pVelocity = Vector2.ClampMagnitude(pVelocity + input / 2, 25);
}
else
{
pVelocity *= new Vector2(2, 2) * Time.deltaTime;
}
}
最佳答案
看来我有点白痴。
如果我真的在球员旋转时在他的轴上观察超过一秒钟,我会看到 Y 始终是他的面向方向,所以我所要做的就是在 y 轴上缩放。
固定代码:
if (curState == state.stretching)
{
rBody.velocity = new Vector2(0,0); //so we don't keep our momentum if we try to stretch while walking
transform.rotation = Quaternion.LookRotation(playerBody.transform.forward, input);
transform.localScale = new Vector3(1,1+pVelocity.magnitude/8,1);
//we move back as the player scales
transform.position = orgPos + new Vector3(pVelocity.x/8,pVelocity.y/8,0);
if (input.magnitude > 0)
{
pVelocity = Vector2.ClampMagnitude(pVelocity + input / 2, 25);
}
else
{
pVelocity *= new Vector2(2, 2) * Time.deltaTime;
}
}
关于c# - 向前拉伸(stretch)我旋转的球员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51643971/