private void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Platform")) { AttachToObject(other.gameObject); } else if (other.CompareTag("Ground") || other.CompareTag("Wall")) { grappleShooter.Detach(); } else if (other.CompareTag("Player") && other.GetComponent <PlayerInfo>() && grappleShooter != other.GetComponent <GrappleShooter>()) { //other.GetComponent<PlayerInfo>().Stun(); //other.GetComponent<Rigidbody2D>().velocity = Vector2.zero; //other.GetComponent<PlayerInfo>().Push(GetComponent<Rigidbody2D>().velocity); //other.GetComponent<QuickHook>().Detach(); AttachToObject(other.gameObject); } }
public void Stun(float duration = 1f) { grappleShooter.Detach(); isStunned = true; StartCoroutine(WaitForStun(duration)); }
// Update is called once per frame void Update() { if (playerInfo.CanAct()) { if (levelOfDifficulty >= 2) { if (punchTarget) { pShooter.aimPunch.AimAt(punchTarget.transform.position); } if (!pShooter.isPunchLoaded) { if (Random.Range(0.0f, 1000.0f) < 10) { pShooter.LoadPunch(); if (levelOfDifficulty >= 3) { foreach (PlayerInfo p in allPlayers) { if (p.transform.position.y < playerInfo.transform.position.y) { punchTarget = p; } } } else { punchTarget = allPlayers[Random.Range(0, allPlayers.Count)]; } if (punchTarget == null) { punchTarget = allPlayers[Random.Range(0, allPlayers.Count)]; } pShooter.aimPunch.SetAimDirection(punchTarget.transform.position); } } if (pShooter.isPunchLoaded) { if (Random.Range(0.0f, 1000.0f) < 10) { pShooter.ReleasePunch(); } else { pShooter.PunchHeld(); } } } if (!hooked && !shot && (Game.instance && !Game.instance.GameOver())) { if (transform.position.y - Ground.position.y < WallDist && shot == false) { shot = true; GameObject[] Platforms = GameObject.FindGameObjectsWithTag("Platform"); if (Platforms.Length > 0) { GameObject closestPlatform = null; float closestDist = Mathf.Infinity; foreach (GameObject Platform in Platforms) { if (Platform.transform.position.y >= transform.position.y && Vector2.Distance(transform.position, Platform.transform.position) < closestDist) { if (Vector2.Distance(Platform.transform.position, transform.position) > 2 && Platform.transform != target) { closestPlatform = Platform; closestDist = Vector2.Distance(transform.position, Platform.transform.position); } } } if (closestPlatform == null) { Debug.Log("No plat found"); return; } aimGrapple.AimAt(closestPlatform.transform.position); target = closestPlatform.transform; targetPlatform = target.gameObject; qHook.Shoot(); } } } if (Camera.main.WorldToViewportPoint(qHook.transform.position).y > 1) { qHook.Detach(); } if (hooked) { if (target) { if (Vector2.Distance(target.position, transform.position) < 3 || AIrb2d.velocity.y < 0) { qHook.Detach(); } } } } }