Forum begins after the advertisement:


[Part 7] Falling Corpse & Shade

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 7] Falling Corpse & Shade

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #15459
    Wan Laeta
    Participant
    Helpful?
    Up
    0
    ::

    I’ve got a problem: The Corpse and Shade falling down when Player dies.
    I have no idea what I did wrong. What should I do now?

    View post on imgur.com

    #15461
    Joseph Tang
    Moderator
    Helpful?
    Up
    0
    ::

    Could you send your PlayerController script’s Death() method code? And can you check your Console to see if there are any errors while in death?

    The reason behind why your player is falling is due to us turning off the boxcollider2D with the line GetComponent<BoxCollider2D>().enabled = false; in the method. Thus, the player no longer has collision detection and falls through the floor. I added this code to prevent other enemies or moving structures from pushing the player’s corpse around.

    However, because the player can fall through the floor, i also added a code rb.constraints = RigidbodyConstraints2D.FreezePosition; to freeze the player’s position when they die, so that they would not move in death animation.

    Therefore, either your Death() method does not include the rigid body line, or you encountered an error with the code.

    As for your shade, it’s likely only falling due to the player fphasing through the ground first and then spawning the shade while under the ground.
    So, I have a feeling that the shade will be fine when the player is fine.

    #15462
    Wan Laeta
    Participant
    Helpful?
    Up
    0
    ::

    Oh! I see my problem.
    This is my Death() code:

    IEnumerator Death()
        {
            pState.alive = false;
            Time.timeScale = 1f;
            GameObject _bloodSpurtParticles = Instantiate(bloodSpurt, transform.position, Quaternion.identity);
            Destroy(_bloodSpurtParticles, 1.5f);
            anim.SetTrigger("Death");
            rb.constraints = RigidbodyConstraints2D.FreezeRotation;
            GetComponent<BoxCollider2D>().enabled = false;
    
            yield return new WaitForSecondsRealtime(0.9f);
            StartCoroutine(UIManager.Instance.ActivateDeathScreen());
    
            yield return new WaitForSeconds(0.9f);
            Instantiate(GameManager.Instance.shade, transform.position, Quaternion.identity);
            // Debug.Log("Instantiate!");
        }

    I used rb.constraints = RigidbodyConstraints2D.FreezeRotation instead rb.constraints = RigidbodyConstraints2D.FreezePosition.
    Thank you for your instructions.

    #15463
    Joseph Tang
    Moderator
    Helpful?
    Up
    0
    ::

    Glad to hear you found the problem!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: