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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #16738
    MI NI
    Level 14
    Bronze Supporter (Patron)
    Helpful?
    Up
    1
    ::

    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.
    #16740
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    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.

    #16749
    MI NI
    Level 14
    Bronze Supporter (Patron)
    Helpful?
    Up
    0
    ::

    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

    #16758
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    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?

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: