Enemies pushing player fixed
This commit is contained in:
parent
99ad7bbe6f
commit
fe3cf2a44c
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,7 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 82006048a5e465e4db1a548c7ec3cece
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -10,7 +10,9 @@ public class EnemyPathFinding : MonoBehaviour
|
||||||
[SerializeField] public Transform[] targets;
|
[SerializeField] public Transform[] targets;
|
||||||
|
|
||||||
[SerializeField] private float ropeDistCheck = 1f;
|
[SerializeField] private float ropeDistCheck = 1f;
|
||||||
|
[SerializeField] private float stopBeforeTargetOffset = 1f;
|
||||||
[SerializeField] private LayerMask ropeCheckMask;
|
[SerializeField] private LayerMask ropeCheckMask;
|
||||||
|
private bool isCollidingWithTarget;
|
||||||
|
|
||||||
private HealthComponent healthComponent;
|
private HealthComponent healthComponent;
|
||||||
|
|
||||||
|
@ -20,9 +22,11 @@ public class EnemyPathFinding : MonoBehaviour
|
||||||
agent = GetComponent<NavMeshAgent>();
|
agent = GetComponent<NavMeshAgent>();
|
||||||
agent.updateRotation = false;
|
agent.updateRotation = false;
|
||||||
agent.updateUpAxis = false;
|
agent.updateUpAxis = false;
|
||||||
|
agent.baseOffset = 0;
|
||||||
|
|
||||||
healthComponent = GetComponent<HealthComponent>();
|
healthComponent = GetComponent<HealthComponent>();
|
||||||
healthComponent.OnHealthZero.AddListener(Rumble);
|
healthComponent.OnHealthZero.AddListener(Rumble);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Rumble()
|
private void Rumble()
|
||||||
|
@ -42,8 +46,12 @@ public class EnemyPathFinding : MonoBehaviour
|
||||||
Vector2 dir = closestTarget.position - transform.position;
|
Vector2 dir = closestTarget.position - transform.position;
|
||||||
if (Physics2D.Raycast(transform.position, dir.normalized, ropeDistCheck, ropeCheckMask)) return;
|
if (Physics2D.Raycast(transform.position, dir.normalized, ropeDistCheck, ropeCheckMask)) return;
|
||||||
|
|
||||||
|
try
|
||||||
try { agent.SetDestination(closestTarget.position); } catch { }// Fuck this error.
|
{
|
||||||
|
if (!isCollidingWithTarget)
|
||||||
|
agent.SetDestination(closestTarget.position);
|
||||||
|
}
|
||||||
|
catch { }// Fuck this error.
|
||||||
}
|
}
|
||||||
|
|
||||||
private Transform GetClosestTarget()
|
private Transform GetClosestTarget()
|
||||||
|
@ -61,4 +69,21 @@ public class EnemyPathFinding : MonoBehaviour
|
||||||
}
|
}
|
||||||
return shortest;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,2 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 6a3ffc4a3af9e0243ac9ee0c995bb82f
|
guid: 6a3ffc4a3af9e0243ac9ee0c995bb82f
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
|
|
Loading…
Reference in New Issue