c# - 需要帮助修复这个跳跃缓冲区(问题:玩家偶尔会双跳)
问题描述
我尝试制作一个简单的跳转缓冲区和 Coyote 计时器。如您所见,有时玩家会进行二段跳,但前提是跳按钮的点击速度非常快。
正如您在 <这里> 看到的那样,它只发生了几次。
[Header("Player Accesiblility")]
public float hangTime = 1.5f;
[SerializeField]
private float hangCounter;
[SerializeField]
private float jumpTimer;
public float jumpDelay = 0.25f;
private void FixedUpdate()
{
if (jumpTimer > Time.time && coll.onGround)
{
Jump(Vector2.up, false);
}
}
Void update(){
if (coll.onGround) //Coyote Time for Jump
{
hangCounter = hangTime;
}
if (Input.GetButtonDown("Jump")) //Jump Function
{
anim.SetTrigger("jump");
jumpTimer = Time.time + jumpDelay;
if (!coll.onGround && hangCounter > 0)
{
Jump(Vector2.up, false);
hangCounter = 0;
}
if (coll.onWall && !coll.onGround)
{
WallJump();
}
}
}
private void Jump(Vector2 dir, bool wall)
{
rb.velocity = new Vector2(rb.velocity.x, 0);
rb.velocity += dir * jumpForce;
jumpTimer = 0f;
hangCounter = 0;
}
任何帮助将不胜感激,并感谢您的时间。
解决方案
我从@Mateusz 那里得到了帮助我的答案。他的评论:这很可能是因为你在 Update 而不是在 FixedUpdate 中做物理。阅读本文以了解更多信息(https://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html)
推荐阅读
- python - flask WTForm:“在应用程序上下文之外工作”
- r - 如何建立纵向 CFA 的配置模型?
- jenkins - 未设置参数化凭据时跳过 Jenkins 阶段
- flutter - 在其他 json 对象 Flutter 中获取一个 json List 对象
- angular - 为什么 Angular 的依赖注入需要私有或公共才能工作?
- moleculer - 列出分子 http 入口点
- java - 如何覆盖 Spring Cloud GCP 中的默认 Spanner 转换器之一
- sql - oracle删除重复的三个组合
- ios - 如何在按下按钮后更新 UI?
- node.js - 使用 json 文件发布请求