首页 > 解决方案 > 人物跳跃有时更强

问题描述

我正在尝试制作一个 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;
    }
}

标签: c#unity3d

解决方案


推荐阅读