Beispiel #1
0
    private void CheckGrapplingHook()
    {
        //Grappling Hook
        if (grapplePressed)
        {
            grapplePressed = false;

            if (GameObject.FindGameObjectWithTag("hook") == null && hudRef.GetGrapples() > 0)
            {
                Vector3 pos = this.transform.position;
                if (Mathf.Abs(transform.rotation.eulerAngles.y) < Mathf.Epsilon)
                {
                    pos.x += 0.25f;
                }
                else
                {
                    pos.x -= 0.25f;
                }

                Vector3 delta = Camera.main.ScreenToWorldPoint(Input.mousePosition) - pos;
                float   theta = Mathf.Atan2(delta.y, delta.x);

                float velX = Mathf.Cos(theta) * throwSpeed;
                float velY = Mathf.Sin(theta) * throwSpeed;

                Vector2 vel = new Vector2(velX, velY);

                //Debug.Log("Delta: " + delta + " Theta " + theta + " Rotation " + Mathf.Rad2Deg * -theta);

                float z = Mathf.Rad2Deg * theta + 90.0f;

                GameObject    currentHook = Instantiate(hookRef, pos, Quaternion.Euler(new Vector3(0, 0, z)));
                GrapplingHook gh          = currentHook.GetComponent <GrapplingHook>();

                gh.InitialVelocity(vel.x, vel.y, this.gameObject);
                SoundManagerScript.PlaySound("woosh");
                anim.SetTrigger("Grapple");
                hudRef.NotifyGrapple();
            }
        }
    }