Example #1
0
    private RaycastHit2D UpdateTentTargetPosition()
    {
        //Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector2 mousePosition  = CursorManager.GetCursorWorldPosition();
        Vector2 mouseDirection = CommonUtils.NormalVector(transform.position, mousePosition);
        float   mouseDistance  = CommonUtils.Distance(transform.position, mousePosition);

        mouseObject.transform.position = new Vector3(mousePosition.x, mousePosition.y, 0);
        targetObject.SetActive(false);
        if (gripping)
        {
            if (grippingObject == null || !grippingObject.activeSelf)
            {
                StopGripping();
            }
            //if ( CommonUtils.Distance( grippingObject.transform.position, transform.position ) > m_MaxStretchDistance*2.0f )
            if (CommonUtils.Distance(tentacle.GetEndPosition(), transform.position) > m_MaxStretchDistance * 2.0f)
            {
                StopGripping();
            }
            //targetRenderer.color = Color.white;
            //float d = CommonUtils.Distance(transform.position, mousePosition);
            //if (d < m_MaxStretchDistance) {
            //	mouseObject.transform.position = new Vector3(mousePosition.x, mousePosition.y, 0);
            //} else {
            //	mouseObject.transform.position = new Vector3(transform.position.x + mouseDirection.x * m_MaxStretchDistance, transform.position.y + mouseDirection.y * m_MaxStretchDistance, 0);
            //}
            return(new RaycastHit2D());
        }
        else
        {
            // Cast from cursor position to player position
            Vector2      playerDirection = CommonUtils.NormalVector(mousePosition, transform.position);
            RaycastHit2D hit             = Physics2D.Raycast(mousePosition, playerDirection, mouseDistance, m_WhatIsGrabbable);


            if (hit.collider == null)
            {
                //Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                //Vector2 mouseDirection = CommonUtils.NormalVector(transform.position, mousePosition);
                // cast from cursor position out to max distance
                hit = Physics2D.Raycast(transform.position, mouseDirection, m_MaxStretchDistance, m_WhatIsGrabbable);
            }

            if (hit.collider != null)
            {
                targetObject.SetActive(true);
                targetObject.transform.position = hit.point;
                //targetRenderer.color = Color.green;
            }
            else
            {
                //targetRenderer.color = Color.white;
                //float d = CommonUtils.Distance(transform.position, mousePosition);
                //if (d < m_MaxStretchDistance) {
                //	mouseObject.transform.position = new Vector3(mousePosition.x, mousePosition.y, 0);
                //} else {
                //	mouseObject.transform.position = new Vector3(transform.position.x + mouseDirection.x * m_MaxStretchDistance, transform.position.y + mouseDirection.y * m_MaxStretchDistance, 0);
                //}
            }

            return(hit);
        }
    }