本文介绍了释放键后立即停止字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个简单的字符控制器.

I'm trying to make a simple character controller.

void Update () 
{
    var x = Input.GetAxis("Horizontal") * Time.deltaTime * 6;
    var z = Input.GetAxis("Vertical") * Time.deltaTime * 6;

    Vector3 direction = Quaternion.AngleAxis(45,Vector3.up) * new Vector3(x, 0, z);

    transform.Translate(direction);
}

但是,这件事有加速和减速的不良作用.当我按下按钮时,它会加速到最大速度并保持运动,而当我松开按钮时,它会缓慢减速.但我希望它立即停止.如果按此按钮,速度应为最大值,释放时应为0.

But this thing has the unwanted effect of speed up and slow down. When I press the button it speeds up to max speed and keeps moving, and when I release it smoothly slows down. But I want it to stop instantly. If I press the button, speed should be the maximum value and 0 when released.

推荐答案

使用 Input.GetAxisRaw 不会应用平滑过滤.它应该立即停止而不是逐渐减速.

Use Input.GetAxisRaw which does not apply smoothing filtering. It should stop right away instead of gradually slowing down.

void Update () 
{
    var x = Input.GetAxisRaw("Horizontal") * Time.deltaTime * 6;
    var z = Input.GetAxisRaw("Vertical") * Time.deltaTime * 6;

    Vector3 direction = Quaternion.AngleAxis(45,Vector3.up) * new Vector3(x, 0, z);

    transform.Translate(direction);
}

这篇关于释放键后立即停止字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 13:47