角色跳跃有时会更强

时间:2018-09-04 08:05:07

标签: c# unity3d

我正在尝试制作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函数会影响我的跳跃物理学吗?如果是这样,我该如何解决我目前遇到的这一跳跃问题? ty。

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;
    }
}

0 个答案:

没有答案