Forum begins after the advertisement:


[General] Prevent the enemy from pushing the player when dealing damage?

Home Forums Video Game Tutorial Series Creating a Rogue-like Shoot-em Up in Unity [General] Prevent the enemy from pushing the player when dealing damage?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #12357
    Logique
    Level 10
    Former Patron
    Helpful?
    Up
    0
    ::

    From your Vampire Survivors Unity Tutorial, the current interaction is that when the player comes into contact with the enemy. They push you. I want to remove this and I tried updating the EnemyStats.cs to comment out the knockback as well tried updating the knockback force. Both does not work.

    I cannot find the code for knockback as well in the PlayerStats.cs

    The only instances of knockback is in EnemyStats.cs and EnemyMovement.cs

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

    Hi Logique, thanks for dropping in to the stream just now. If I had known your question was simple I would’ve answered it in the stream. My bad.

    The pushing is not caused by damage knockback. It is caused because both the enemies and the player have a solid collider. You need to disable the solid collider on the player by checking its Is Trigger attribute, but this will cause the enemy to be unable to damage the player, because the damage only happens on a collision.

    To restore enemies damaging the player, you need to the following to EnemyStats.cs to get triggers to register damage:

        void OnTriggerStay2D(Collider2D col)
        {
            //Reference the script from the collided collider and deal damage using TakeDamage()
            if (col.gameObject.CompareTag("Player"))
            {
                PlayerStats player = col.gameObject.GetComponen<PlayerStats>();
                player.TakeDamage(currentDamage); // Make sure to use currentDamage instead of weaponData.Damage in case any damage multipliers in the future
            }
        }

    Hope this makes sense!

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

Go to Login Page →


Advertisement below: