c# - Unity3d 新的输入系统逐步增加/减少值,而不是立即从 0 到 1 或 -1
问题描述
我使用 1D 轴进行运动,但值立即从 0 变为 1 或 -1 我需要逐渐增加和减少值,就像 Input.GetAxis() 而不是 Input.GetAxisRaw();
现在我正在阅读这样的输入
float value = controlSystem.DroneInput.Throttle.ReadValue<float>();
drone.AddRelativeForce(0, value * throttle * 100, 0, ForceMode.Force);
解决方案
我会用Mathf.SmoothDamp
这样的简单缓动:
(从上面链接的文档页面采用的代码)
using UnityEngine;
public class Example : MonoBehaviour
{
float smoothTime = 0.3f;
float smoothingV = 0.0f;
float currentValue = 0.0f;
void Update()
{
float target = controlSystem.DroneInput.Throttle.ReadValue<float>();
currentValue = Mathf.SmoothDamp(currentValue, target, ref smoothingV, smoothTime);
drone.AddRelativeForce(0, newValue * throttle * 100, 0, ForceMode.Force);
}
}
推荐阅读
- java - Eclipse 启动的 Maven 项目不使用 \target 文件夹中的类
- javascript - 使用 JavaScript 在点击时更新元素的 CSS
- cucumber - 空手道框架 - 如何检查两个字符串的条件或属性
- amazon-web-services - 如何从 JMeter 生成 AWS 签名?
- javascript - axios 请求拦截器错误处理程序中错误对象的形状是什么?
- java - reactor.netty.http.server.AccessLog 产生 LoggingEvent 而不是 AccessEvent
- mysql - MySQL 陷入 Group BY 和 ONLY_FULL_GROUP_BY 错误
- reactjs - (事件:鼠标事件
) => void' 不可分配给类型 '() => Event' - azure-cognitive-services - 是否可以训练 Azure OCR
- google-fit - 如何获取 google fit 会话的高程数据