Enemies pushing player fixed

This commit is contained in:
kimx100 2024-03-01 21:56:46 +01:00
parent 99ad7bbe6f
commit fe3cf2a44c
4 changed files with 4744 additions and 12 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 82006048a5e465e4db1a548c7ec3cece
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -10,7 +10,9 @@ public class EnemyPathFinding : MonoBehaviour
[SerializeField] public Transform[] targets;
[SerializeField] private float ropeDistCheck = 1f;
[SerializeField] private float stopBeforeTargetOffset = 1f;
[SerializeField] private LayerMask ropeCheckMask;
private bool isCollidingWithTarget;
private HealthComponent healthComponent;
@ -20,9 +22,11 @@ public class EnemyPathFinding : MonoBehaviour
agent = GetComponent<NavMeshAgent>();
agent.updateRotation = false;
agent.updateUpAxis = false;
agent.baseOffset = 0;
healthComponent = GetComponent<HealthComponent>();
healthComponent.OnHealthZero.AddListener(Rumble);
}
private void Rumble()
@ -42,8 +46,12 @@ public class EnemyPathFinding : MonoBehaviour
Vector2 dir = closestTarget.position - transform.position;
if (Physics2D.Raycast(transform.position, dir.normalized, ropeDistCheck, ropeCheckMask)) return;
try { agent.SetDestination(closestTarget.position); } catch { }// Fuck this error.
try
{
if (!isCollidingWithTarget)
agent.SetDestination(closestTarget.position);
}
catch { }// Fuck this error.
}
private Transform GetClosestTarget()
@ -61,4 +69,21 @@ public class EnemyPathFinding : MonoBehaviour
}
return shortest;
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
isCollidingWithTarget = true;
agent.stoppingDistance = 100;
}
}
private void OnCollisionExit2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
isCollidingWithTarget = false;
agent.stoppingDistance = 0;
}
}
}

View File

@ -1,11 +1,2 @@
fileFormatVersion: 2
guid: 6a3ffc4a3af9e0243ac9ee0c995bb82f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
guid: 6a3ffc4a3af9e0243ac9ee0c995bb82f