问题:我的玩家就像我总是拿着“w”键一样。
所以我试着使用第一人称一体机以及简单的fps播放器控制器。我使用输入系统管理器和可视化工具仔细检查了输入系统,拔掉了除键盘和鼠标之外的所有usb设备,没有发现任何异常输入被检测到。即使没有插入usb设备,播放器也可以行走。
因此,多个项目文件中的多个播放器预置,无论是urp还是3d,即使我拔下了每个usb设备,也会像检测到前向行走输入一样工作。我不知所措
发布于 2021-08-04 04:34:56
确保没有将速度设置为始终增加。使其仅在按下“w”键时增加。这是我用来移动球员的代码-
//Input
float x, y;
bool jumping, sprinting, crouching;
//Movement
public float moveSpeed = 4500;
public float maxSpeed = 20;
private void Update()
{
MyInput();
}
private void MyInput()
{
x = Input.GetAxisRaw("Horizontal");
y = Input.GetAxisRaw("Vertical");
}
private void Movement()
{
//Extra gravity
rb.AddForce(Vector3.down * Time.deltaTime * 10);
Vector2 mag = FindVelRelativeToLook();
float xMag = mag.x, yMag = mag.y;
CounterMovement(x, y, mag);
//Set max speed
float maxSpeed = this.maxSpeed;
//If speed is larger than maxspeed, cancel out the input so you don't go over max speed
if (x > 0 && xMag > maxSpeed) x = 0;
if (x < 0 && xMag < -maxSpeed) x = 0;
if (y > 0 && yMag > maxSpeed) y = 0;
if (y < 0 && yMag < -maxSpeed) y = 0;
//Some multipliers
float multiplier = 1f, multiplierV = 1f;
// Movement in air
if (!grounded)
{
multiplier = 0.3f;
multiplierV = 0.3f;
}
//Apply forces to move player
rb.AddForce(orientation.transform.forward * y * moveSpeed * Time.deltaTime * multiplier * multiplierV);
rb.AddForce(orientation.transform.right * x * moveSpeed * Time.deltaTime * multiplier);
}希望这会对你有所帮助。
谢谢。
https://stackoverflow.com/questions/68641698
复制相似问题