Forum begins after the advertisement:
[General] Player injuries and monster attacks
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [General] Player injuries and monster attacks
- This topic has 3 replies, 2 voices, and was last updated 1 month, 1 week ago by Terence.
-
AuthorPosts
-
December 11, 2024 at 9:06 pm #16738::
I found that if the player is injured in a corner, the monster will continue to advance towards the player, causing the player to get stuck on the wall and be injured again after the invincibility ends. In addition, if the player jumps on top of the bat, although he will be injured, he will not leave voluntarily. In the case of bats, the player will continue to fly upward until death. Is there any good way to solve this problem?
has upvoted this post. December 11, 2024 at 11:13 pm #16740::We can introduce a new state to enemies that only runs when an enemy detects that the player is in an invulnerable state, and code a behaviour for the enemy to perform when the player is invulnerable.
Does this make sense?
P.S. This is a great question.
December 13, 2024 at 10:14 am #16749::I observed HollowKnight’s approach. When the character is injured, the character will bounce back and keep a distance from the monster. It seems that the layer collision with the monster will be temporarily released. My idea is to temporarily close the layer collision with the monster when the player is injured. layer collision. As for bouncing the player backwards, I find it a bit difficult to implement.
I think if a new behavior is introduced when the player is invincible, I am not sure whether it can solve the problem of bats. For example, I made a parkour map with some monsters in it, and then I jumped on top of the bat, although I would continue to be injured. But the bat will keep moving towards me and I will be able to ride on it to the finish line
My emails seem weird, I can’t get replies to them
December 13, 2024 at 6:53 pm #16758::Making the player unable to collide with enemies temporarily after getting hit is a good idea. You can also introduce a recoil by setting
pState.recoilingX
to true whenever the player takes damage. That should push you out of the range of the bat:public void TakeDamage(float _damage) { if(pState.alive) { pState.recoilingX = true; audioSource.PlayOneShot(hurtSound); Health -= Mathf.RoundToInt(_damage); if(Health <= 0) { Health = 0; StartCoroutine(Death()); } else { StartCoroutine(StopTakingDamage()); } } }
There is a better way to implement recoil–ideally, it should be coded as a function that can be called anytime you need it. The current way recoil is coded is clunky and suboptimal.
You can look at part 13 of the Vampire Survivors tutorial to see an example: https://blog.terresquall.com/2023/09/creating-a-rogue-like-vampire-survivors-part-13/
What is the issue with the emails?
-
AuthorPosts
- You must be logged in to reply to this topic.