Forum begins after the advertisement:


[Part 3.5] Bug in code making the enemy recoil towards the player

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 3.5] Bug in code making the enemy recoil towards the player

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #19147
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    Reposting a useful comment from @cryst2000 on YouTube.

    I think there is a bug in your code here that makes the enemy recoil towards you as well as the enemy is getting hit more than once. This is the fix.
    // Store player recoil direction (away from enemy)
    recoilDirection = (transform.position - objectsToHit[i].transform.position).normalized;
    
    // Send enemy recoil direction (away from player)
    e.EnemyHit(damage, (objectsToHit[i].transform.position - transform.position).normalized, _recoilStrength);
    
    hitEnemies.Add(e); // Mark this enemy as "already hit this swing"
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: