【发布时间】:2019-09-23 14:03:21
【问题描述】:
大家好,这里是新手。
自上而下的塞尔达风格游戏。
我正试图弄清楚如何让我的播放器建立速度到最大速度然后降低速度到停止。
我已经使用 GetRawAxis 进行了移动,但是当我使用此方法按下移动时,我的字符以最大速度移动。
private void PlayerMovement()
{
var playerMovement = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")).normalized * Time.deltaTime * moveSpeed;
transform.position = new Vector3(
transform.position.x + playerMovement.x,
transform.position.y + playerMovement.y,
transform.position.z);
}
【问题讨论】:
-
请提供代码和/或更多信息
-
你可以尝试使用 RigidBody 的
AddForce在摇杆的方向上,而不是设置速度,并添加一些阻力以使他在没有主动施加力的情况下缓慢停止 -
这是我当前的移动方法 private void PlayerMovement() { var playerMovement = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")).normalized * Time.deltaTime *移动速度; transform.position = new Vector3(transform.position.x + playerMovement.x, transform.position.y + playerMovement.y, transform.position.z); }
-
抱歉不知道如何让代码看起来正常
-
@Tas7e 嘿,我在这里看到了你刚刚删除的问题:stackoverflow.com/questions/67320573/… 我正要发布答案,所以无论如何希望它对 pastebin.com/6ZRed1eu 有所帮助
标签: c# unity3d acceleration