public void handleDash(TentacleAnimation tentacleAnim) { if (!canJump) { return; } Vector2 mouse = Input.mousePosition; mouse = (Vector2)Camera.main.ScreenToWorldPoint(mouse); RaycastHit2D ray = Physics2D.Linecast(transform.position, mouse, 1 << LayerMask.NameToLayer("Default")); Collider2D coll = ray.collider; Transform ikTarget = tentacleAnim.IKTipOfTentacle; this.AnimateOverTime01(0.3f, j => { Vector2 destination = (Vector2)transform.position + (mouse - (Vector2)this.transform.position).normalized * attackDistance; ikTarget.position = Vector3.Lerp( ikTarget.position, destination, j ); }); if (coll != null) { if (coll.gameObject.layer == LayerMask.NameToLayer("Default")) { if (ray.distance < 3) { tentacleAnim.PlayHitSound(0.2f); Vector2 v = ((Vector2)transform.position - mouse).normalized; rb.AddForce(v * jumpHeight); } } else { tentacleAnim.PlayAnimSound(0.1f); } if (coll.gameObject.tag == "alien") { if (ray.distance < 3) { //repousse l'alien et damage Vector2 v = (mouse - (Vector2)transform.position).normalized; coll.gameObject.GetComponent <Rigidbody2D>().AddForce(v * dashKnockBackForce); coll.gameObject.GetComponent <LifebarController>().AddHp(-dashDamage); } } } else { tentacleAnim.PlayAnimSound(0.1f); } }
public void handleGun(TentacleAnimation tentacleAnim) { Vector2 mouse = Input.mousePosition; mouse = (Vector2)Camera.main.ScreenToWorldPoint(mouse); Vector3 orientation = (mouse - (Vector2)this.transform.position).normalized; GameObject shoot = (GameObject)GameObject.Instantiate(shot, this.transform.position + orientation, Quaternion.identity); shoot.GetComponent <Rigidbody2D>().AddForce(orientation * 1000); tentacleAnim.PlayAnimSound(0.1f); //shoot.GetComponent<Rigidbody2D>().AddForce(new Vector2(1000 * direction, 0)); }
public void handleShield(TentacleAnimation tentacleAnim) { if (!hasShield) { return; } if (shieldSpawned) { return; } Vector2 mouse = Input.mousePosition; mouse = (Vector2)Camera.main.ScreenToWorldPoint(mouse); Transform ikTarget = tentacleAnim.IKTipOfTentacle; Transform ikbaseTarget = tentacleAnim.IKBase; tentacleAnim.PlayAnimSound(0.5f); this.AnimateOverTime01(anticipationDuration, i => { ikTarget.position = Vector3.Lerp( ikTarget.position, transform.position + new Vector3(0, 0.2f, 0), i ); ikbaseTarget.position = Vector3.Lerp( ikbaseTarget.position, transform.position, i ); if (i == 1) { Vector2 v = (mouse - (Vector2)transform.position).normalized; GameObject shieldSpawner = (GameObject)GameObject.Instantiate(shieldSpawn, transform.position + (Vector3)v * 2, Quaternion.Euler(0, 0, v.y > 0 ? Vector2.Angle(Vector2.right, v) : Vector2.Angle(Vector2.left, v))); shieldSpawner.transform.parent = this.transform; shieldSpawner.transform.localScale = Vector3.one * 4; shieldSpawned = true; tentacleAnim.PlayHitSound(0.5f); this.AnimateOverTime01(0.4f, j => { ikTarget.position = transform.position + new Vector3(0, 0.2f, 0); ikbaseTarget.position = Vector3.Lerp( ikbaseTarget.position, shieldSpawner.transform.position, i * 2 ); }); } }); }
public void handleTentacle(TentacleAnimation tentacleAnim) { if (!hasTentacle) { return; } Transform ikTarget = tentacleAnim.IKTipOfTentacle; this.AnimateOverTime01(anticipationDuration, i => { ikTarget.position = Vector3.Lerp( ikTarget.position, transform.position, i ); if (i == 1) { tentacleAnim.PlayAnimSound(0.2f); this.AnimateOverTime01(actionDuration, j => { Vector2 mouse = (Vector2)Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 destination = (Vector2)transform.position + (mouse - (Vector2)this.transform.position).normalized * attackDistance; ikTarget.position = Vector3.Lerp( ikTarget.position, destination, j ); if (j == 1) { Debug.DrawLine(transform.position, destination); RaycastHit2D ray = Physics2D.Linecast(transform.position, destination, 1 << LayerMask.NameToLayer("Default")); Collider2D coll = ray.collider; if (coll != null) { tentacleAnim.PlayHitSound(0.4f); Debug.Log(coll.gameObject.tag); if (coll.gameObject.tag == "alien") { Vector2 v = (mouse - (Vector2)transform.position).normalized; coll.gameObject.GetComponent <Rigidbody2D>().AddForce(v * dashKnockBackForce); coll.gameObject.GetComponent <LifebarController>().AddHp(-attackDamage); } } } }); } }); }