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
- This topic has 3 replies, 2 voices, and was last updated 1 year, 3 months ago by
Joseph Tang.
-
AuthorPosts
-
July 31, 2024 at 5:38 pm #15459::
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
August 1, 2024 at 1:15 pm #15461::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.
August 1, 2024 at 4:38 pm #15462::Oh! I see my problem. This is my
Death()code:<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!"); }</code>I used
rb.constraints = RigidbodyConstraints2D.FreezeRotationinsteadrb.constraints = RigidbodyConstraints2D.FreezePosition. Thank you for your instructions.August 1, 2024 at 5:38 pm #15463 -
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: