c# - 人物跳跃有时更强
问题描述
我正在尝试制作一个 2d 横向卷轴平台游戏,我遇到了一个问题,我的角色的跳跃力不稳定。有时角色会按照我预期的方式跳跃,但我认为根据我的观察,我的角色的跳跃力会越来越低。任何人都可以帮助我并解释灵魂?谢谢!
public bool isgrounded;
public float groundradius;
public Transform checkslot;
public LayerMask LM;
public float jumpower;
void FixedUpdate()
{
if (isgrounded && Input.GetKeyDown(KeyCode.UpArrow) && myrb.velocity.y <= 0.0f)
{
isgrounded = false;
jumping = true;
myanim.SetBool("groundedanim", isgrounded);
myrb.AddForce(new Vector2(0, jumpower), ForceMode2D.Impulse);
}
isgrounded = Physics2D.OverlapCircle(checkslot.position, groundradius, LM);
myanim.SetBool("groundedanim", isgrounded);
myanim.SetFloat("verticalspeed", myrb.velocity.y);
好的,我添加了这个额外的信息,那么Dash
我包含的这个功能FixedUpdate
会影响我的跳跃物理吗?如果是这样,我该如何解决我目前遇到的这个跳跃问题?泰。
public float dashspeed;
float dashtime;
public float startdash;
int direction;
public bool isleft;
public bool isRight;
public bool isClickDash;
void Start () {
dashtime = startdash;
}
void FixedUpdate ()
{
Dash();
}
public void Dash()
{
if (direction == 0)
{
if (isleft)
{
direction = 1;
}
else if (isRight)
{
direction = 2;
}
}
else
{
if (dashtime <= 0)
{
direction = 0;
dashtime = startdash;
myrb.velocity = Vector2.zero;
if (dashtime == startdash)
{
isClickDash = false;
myanim.SetInteger("TriggerDash", 0);
}
}
else
{
dashtime -= Time.deltaTime;
if (direction == 1)
{
if (isClickDash)
{
DashNow();
}
}
else if (direction == 2)
{
if (isClickDash)
{
DashNow();
}
}
}
}
}
public void DashNow()
{
isClickDash = true;
myanim.SetInteger("TriggerDash", 1);
if (isRight)
{
myrb.velocity = Vector2.right * dashspeed;
}
else if (isleft)
{
myrb.velocity = Vector2.left * dashspeed;
}
}
解决方案
推荐阅读
- firebase - 如何使用 Nodemcu 将数据上传到 Firebase?
- ios - 如何在音频停止快速播放后自动更改按钮的背景图像?
- angular - 如果数字大于我分配的某个值,则显示“99+”
- python - 在python3的列表理解中使用if、elif和else
- java - 关于Spring框架中@Lazy注解的问题
- powershell - 将 System.Object 加载到 DataGrid 中
- c++ - 如何将 gmock 函数分配给特定的函数指针?
- javascript - 如何在其他 App Container - React Navigation 中获取参数?
- flutter - ListView 复选框被同时选中
- java - 如何声明并添加到全局数组列表?