【问题标题】:Returning platform shakes before setting active设置活动前返回平台抖动
【发布时间】:2020-09-02 10:03:02
【问题描述】:

我在 Unity 上制作 2D 游戏,但渲染和移动顺序有问题。 我有一个脚本制作平台,当玩家踩到它时会掉落并消失。这是我的脚本的主要部分:

void OnCollisionEnter2D (Collision2D col)
{
    if (col.gameObject.name.Equals("Player") && player.GetComponent<PlayerController>().IsGrounded() && !platformMovingBack) 
    {
        Invoke ("DropPlatform", 1f);
    }
}

void DropPlatform()
{
    rb.isKinematic = false;
    Invoke("DestroyPlatform", 0.4f);
    Invoke ("GetPlatformBack", 1.4f);
    Invoke("ResurrectPlatform", 2f);
}

void GetPlatformBack()
{
    rb.velocity = Vector2.zero;
    platformMovingBack = true;
}

void DestroyPlatform()
{
    transform.gameObject.SetActive(false);
}

void ResurrectPlatform()
{
    rb.isKinematic = true;
    transform.gameObject.SetActive(true);
}
void Update()
{

    if (platformMovingBack)
    {
        transform.position = initialPosition;
        transform.rotation = initialRotation;
        platformMovingBack = false;
    }
}

但是我有一个问题。尽管平台在所有执行后才变得活跃,但在游戏中我看到平台摇晃并向上移动。我做错了什么?

【问题讨论】:

    标签: c# unity3d scripting


    【解决方案1】:
    rb.isKinematic = false;
    

    这使得平台会受到外力的影响。始终保持开启状态,如果您需要使用它移动平台,还有很多其他方法,例如 lerp。

    【讨论】:

    • 我只希望玩家在开始向下移动时能够跳跃。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    • 2015-07-19
    相关资源
    最近更新 更多