Unity RigidBody2D悬停无法在某些计算机上运行

时间:2018-07-26 14:26:04

标签: c# unity3d hover 2d

您好,我制作了2D游戏并实现了悬停效果(浮动)。

首先,我的“ bodybody2D”组件选项是自爆图片。

this is my rigidbody 2D

然后按住X按钮,使悬停功能正常工作。

下面是我创建的源。

void Update()
{
    CheckJump();
    CheckRavitate();

    DoingAction();
}

void DoingAction()
{
     if (this.IsStatus(CustomCharacterInfo.CHAR_STATUS.JUMP))
     {
         // Jump
         this.rigid2D.AddForce(transform.up * JUMP_FORCE);
         nowStatus &= ~CustomCharacterInfo.CHAR_STATUS.JUMP;
     }

     if (IsStatus(CustomCharacterInfo.CHAR_STATUS.RAVITATE))
     {
         RaycastHit2D rayHitData = Physics2D.Raycast(
                 new Vector2(transform.position.x, transform.position.y),
                 new Vector2(0, -1.0f),0.5f,
                 1 << GlobalLayerMask.TERRIAN_MASK);
         bool canRavitate = rayHitData.collider ? false : true;
         Debug.DrawRay(transform.position, new Vector2(0, -0.8f),Color.green);
         if (canRavitate)
         {
             float yVel = Physics.gravity.y;
             Debug.Log("Ravitae FORECE " + yVel);

             //Howering
             rigid2D.AddForce(new Vector2(0, -yVel), ForceMode2D.Force);
         }
     }
}

/*
My intention is that when the x key is pressed for more than 0.05 seconds, 
the floating flag is turned on.
When you release x, it will be off.
*/
void CheckRavitate()
{
    if (true)
    {
        if (Input.GetKey(KeyCode.X))
        {
            if (raviValue.canRavitate && Time.time - raviValue.tDown > 0.05f && rigid2D.velocity.y < 0.2f)
            {
                Debug.Log("RAVITATE FLAG ON");
                nowStatus |= CustomCharacterInfo.CHAR_STATUS.RAVITATE;
                rigid2D.velocity = new Vector2(0.0f, 0.0f);
                raviValue.canRavitate = false;
            }
        }

        if (this.IsStatus(CustomCharacterInfo.CHAR_STATUS.RAVITATE) && Input.GetKeyUp(KeyCode.X))
        {
            nowStatus &= ~CustomCharacterInfo.CHAR_STATUS.RAVITATE;
            raviValue.canRavitate = true;
        }
    }
}



void CheckJump()
{

    // Jump Function
    if (Input.GetKeyDown(KeyCode.X) && jumpcount > 0)
    {
        isGrounded = false;
        nowStatus |= CustomCharacterInfo.CHAR_STATUS.JUMP;
        jumpcount--;
        raviValue.tDown = Time.time;
    }
}

public class RavitateFlag
{
    public float tDown;
    public bool canRavitate;
    public RavitateFlag()
    {
        tDown = Time.time;
        canRavitate = true;
    }
}

结果低于该值

Error Motion

那是errormotion捕获

enter image description here

那是正确的动作捕捉

该问题不适用于播放器的计算机。

我不知道为什么会有所不同。代码相同,日志也相同。

如果将一个重力刻度更改为1,则浮动功能将正常工作。

但是我认为这不是解决方案。另外,当您将重力比例更改为1时,正常操作的角色将飞向天空。

我想是时候调用更新函数了,但这还不清楚。

0 个答案:

没有答案