Пример #1
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        // on collision with wall when not hooked, hook into wall
        if (collision.gameObject.tag == "Wall" && !hooked && !retracting)
        {
            grappleOriginOffset = grapple_Component.grappleOrigin.transform.position - grapple_Component.transform.position;

            // set point for player to lock onto
            //lockPoint.transform.position = collision.ClosestPoint(grapple_Component.player_Component.transform.position);

            //lockPoint.transform.position = collision.otherCollider.ClosestPoint(transform.position);
            lockPoint.transform.position = collision.collider.ClosestPoint(transform.position);

            //lockPoint.transform.position += new Vector3(grapple_Component.player_Component.facingDirection.x * -.48f, 0,0);
            lockPoint.transform.position  = (lockPoint.transform.position + (Vector3.Normalize(grapple_Component.grappleOrigin.transform.position - lockPoint.transform.position) * playerRadiusOffset));
            lockPoint.transform.position -= grappleOriginOffset;
            // hook into wall
            hooked = true;
            //  stop hook
            origin = this.transform.position;
            rb_Component.velocity    = Vector2.zero;
            rb_Component.isKinematic = true;
            // hook lock
            grapple_Component.HookLocked();
        }
    }