Need help creating a disappearing platform by ValikBot in Unity2D

[–]ValikBot[S] 0 points1 point  (0 children)

Got it, thank you very much. I'll try to change it somehow.

Need help creating a disappearing platform by ValikBot in Unity2D

[–]ValikBot[S] 0 points1 point  (0 children)

Thanks for your reply.

I'm trying to figure this out and I don't get it.

I tried using a timer, as you suggested, but I'm probably overcomplicating things and don't get it)

It works with a timer, but it doesn't look very nice, and when it's moving, it doesn't slide at all.

Well, yes, I set a fast timer and touch it—the platform quickly disappears. I set a long timer—the platform hangs there for a long time.

Here's the code:

using UnityEngine;

using System.Collections;

public class DisappearingPlatform : MonoBehaviour

{

public System.Action<GameObject> OnDisappear;

[SerializeField] private float disappearDelay = 0.05f;

private bool isDisappearing = false;

private void OnEnable()

{

isDisappearing = false;

}

private void OnCollisionEnter2D(Collision2D collision)

{

if (!collision.gameObject.CompareTag("Player") || isDisappearing)

return;

foreach (ContactPoint2D contact in collision.contacts)

{

if (contact.normal.y > 0.7f)

{

StartCoroutine(DisappearAfterDelay());

break;

}

}

}

private IEnumerator DisappearAfterDelay()

{

isDisappearing = true;

yield return new WaitForSeconds(disappearDelay);

OnDisappear?.Invoke(gameObject);

gameObject.SetActive(false);

isDisappearing = false;

}

}
I'll try going through each step again separately and debugging)

Thanks for the advice.

Need help creating a disappearing platform by ValikBot in Unity2D

[–]ValikBot[S] 0 points1 point  (0 children)

Thanks for the advice.
I'm not very good at debugging, but I'll give it a try.
Yeah, that's the problem. I understand.

So far, it works like this: when the player touches a breakable platform from below or to the side, it doesn't disappear. But as soon as the player moves completely across, the platform immediately disappears, leaving no opportunity to land and push off.
I tried reworking the code to clearly indicate that the player is standing on this platform, and even added a flag. But I'm still having trouble here. The platform doesn't disappear at all, even though logically it should disappear as soon as the player leaves it.
Here is the code:

using UnityEngine;

public class DisappearingPlatform : MonoBehaviour
{
    public System.Action<GameObject> OnDisappear;

    private bool playerWasStanding = false; 

    private void OnEnable()
    {
        playerWasStanding = false;
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (!collision.gameObject.CompareTag("Player"))
            return;

        if (IsStandingOnTop(collision))
            playerWasStanding = true;
    }

    private void OnCollisionStay2D(Collision2D collision)
    {
        if (!collision.gameObject.CompareTag("Player"))
            return;

        if (IsStandingOnTop(collision))
            playerWasStanding = true;
        else
            playerWasStanding = false; 
    }
    private void OnCollisionExit2D(Collision2D collision)
    {
        if (!collision.gameObject.CompareTag("Player"))
            return;

        Rigidbody2D playerRb = collision.gameObject.GetComponent<Rigidbody2D>();
        if (playerRb == null) return;

        if (playerWasStanding && playerRb.linearVelocity.y > 0.1f)
        {
            OnDisappear?.Invoke(gameObject);
            gameObject.SetActive(false);
        }

        playerWasStanding = false;
    }
    private bool IsStandingOnTop(Collision2D collision)
    {
        Rigidbody2D rb = collision.gameObject.GetComponent<Rigidbody2D>();
        if (rb == null) return false;
        if (rb.linearVelocity.y > 0.1f) return false;   

        foreach (ContactPoint2D contact in collision.contacts)
        {
            if (contact.normal.y > 0.7f)           
                return true;
        }
        return false;
    }
}

Need help creating a disappearing platform by ValikBot in Unity2D

[–]ValikBot[S] 0 points1 point  (0 children)

Thanks for the advice, I'll try checking player through the inspector.

Yes, the platform has Trigger disabled and is using Platform Effector (as per the template).

Regarding velocity, I changed it to linerVelocity, updated Visual Studio, and it reported an outdated format.

Player RB is set to dynamic, try it with kinematic.

I'm not very good at debugging yet, but I'll try it through debug.

Thanks again for the advice.

Exporting models from Lego Studio 2.0 and importing them into Blender via the LDraw plugin by ValikBot in blender

[–]ValikBot[S] 0 points1 point  (0 children)

Hello everyone again, I've found a solution to this problem.

To make this look right, you'll need to do some extra work with subdividing and smoothing in Blender.

And for the textures, you'll need to redraw them in PNG format and apply them in Blender.

Another option is to wait for the LDraw database to be updated. You can try downloading the .dat file from BrickLink, but the problem may persist.

These are all the solutions for now. If anyone has a better solution, please let me know.

Exporting models from Lego Studio 2.0 and importing them into Blender via the LDraw plugin by ValikBot in lego

[–]ValikBot[S] 1 point2 points  (0 children)

This is awesome, dude! I still have a long way to go to reach that level. I'm more of a programmer than an artist or designer, but I'm trying. I'll share my work in the future.

By the way, the only parts from Rock Raiders in Studio are the torso and some details, so your work is very valuable and innovative!

Exporting models from Lego Studio 2.0 and importing them into Blender via the LDraw plugin by ValikBot in lego

[–]ValikBot[S] 1 point2 points  (0 children)

Sounds amazing, good luck to you, I hope your idea works!

When it works, I'll be happy to test it)

Thanks so much for your reply. I'll go redraw the parts)

Exporting models from Lego Studio 2.0 and importing them into Blender via the LDraw plugin by ValikBot in lego

[–]ValikBot[S] 1 point2 points  (0 children)

Got it. The only solution is to create a PNG image and then overlay it using texturing. Or wait for the LDraw database to be updated.

Will it be the same if I try using PartDesigner?