summaryrefslogtreecommitdiff
path: root/GameCode/PlayerAIPetter.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-10-27 11:05:14 +0800
committerchai <215380520@qq.com>2023-10-27 11:05:14 +0800
commit766cdff5ffa72b65d7f106658d1603f47739b2ba (patch)
tree34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/PlayerAIPetter.cs
+ init
Diffstat (limited to 'GameCode/PlayerAIPetter.cs')
-rw-r--r--GameCode/PlayerAIPetter.cs66
1 files changed, 66 insertions, 0 deletions
diff --git a/GameCode/PlayerAIPetter.cs b/GameCode/PlayerAIPetter.cs
new file mode 100644
index 0000000..0c235f5
--- /dev/null
+++ b/GameCode/PlayerAIPetter.cs
@@ -0,0 +1,66 @@
+using UnityEngine;
+
+public class PlayerAIPetter : MonoBehaviour
+{
+ private PlayerAPI api;
+
+ public LayerMask m_layer;
+
+ public AnimationCurve aimCurve;
+
+ public float m_shootRandom = 0.9f;
+
+ public float m_predDist = 1f;
+
+ public float m_timeSinceGround = 0.1f;
+
+ private BoxCollider2D m_collider;
+
+ private void Start()
+ {
+ api = GetComponentInParent<PlayerAPI>();
+ m_collider = api.GetComponentInChildren<BoxCollider2D>();
+ }
+
+ private void Update()
+ {
+ if ((double)Random.Range(0f, 1f) > 0.9)
+ {
+ api.Move(api.TowardsOtherPlayer() * -1f);
+ }
+ else
+ {
+ api.Move(api.TowardsOtherPlayer());
+ }
+ PredictionHit();
+ api.Attack();
+ if ((double)Random.Range(0f, 1f) > 0.9)
+ {
+ api.Jump();
+ }
+ AutoBlock();
+ }
+
+ private void AutoBlock()
+ {
+ foreach (BulletWrapper allBullet in api.GetAllBullets())
+ {
+ RaycastHit2D raycastHit2D = Physics2D.Raycast(allBullet.projectileMovement.transform.position, ((Vector2)allBullet.projectileMovement.velocity).normalized, allBullet.velocity.magnitude * 5f * TimeHandler.deltaTime, m_layer);
+ if ((bool)raycastHit2D.transform && (!allBullet.projectileHit.ownPlayer || allBullet.projectileHit.ownPlayer != api.player) && raycastHit2D.transform.root == base.transform.root)
+ {
+ Debug.Log("BLICOK");
+ api.Block();
+ }
+ }
+ }
+
+ private void PredictionHit()
+ {
+ if ((bool)api.GetOtherPlayer())
+ {
+ float magnitude = (api.OtherPlayerPosition() - base.transform.position).magnitude;
+ Vector2 vector = api.GetOtherPlayer().data.playerVel.velocity * m_predDist * 0.1f * magnitude * 0.05f;
+ api.SetAimDirection(api.TowardsOtherPlayer() + Vector2.up * aimCurve.Evaluate(magnitude) + vector);
+ }
+ }
+}