Example #1
0
 // Stop sticking tongue to object
 private void RetractTongue()
 {
     platformScript   = null;
     intersecting     = false;
     lr.positionCount = 0;
     Destroy(joint);
 }
Example #2
0
    // While swinging, if tongue intersects with an object, move tongue position to intersection point. Only works if on the same object.
    // If intersecting with a different object than what the tongue is currently stuck to, then break the tongue.
    private void IntersectTongue()
    {
        RaycastHit intersect;

        tongueLength = Vector3.Distance(frogViewCam.position, grapplePoint) - 1.0f;
        Vector3 lineDir = (grapplePoint - tongueTip.position);

        if (Physics.Raycast(frogViewCam.position, lineDir.normalized, out intersect, tongueLength, grappleableLayers))
        {
            if (intersect.collider != null)
            {
                if (strongTongue || curAttachedObject == intersect.collider.gameObject)
                {
                    platformScript = curAttachedObject.GetComponent <Spacefloat>();
                    if (platformScript != null)
                    {
                        Debug.Log(platformScript.speed);
                    }
                    grapplePoint          = intersect.point;
                    joint.connectedAnchor = grapplePoint;

                    intersecting          = true;
                    originGrapplePosition = grapplePoint;
                }
                else
                {
                    RetractTongue();
                }
            }
        }
    }
Example #3
0
    // Use Raycast to determine info about which object to shoot tongue at.
    private void ShootTongue()
    {
        RaycastHit hit;

        // Check if there is an object with a layer that the tongue can stick to.
        if (Physics.Raycast(frogViewCam.position, frogViewCam.forward, out hit, maxTongueLength, grappleableLayers))
        {
            if (hit.collider != null)
            {
                curAttachedObject = hit.collider.gameObject;
                platformScript    = curAttachedObject.GetComponent <Spacefloat>();
                if (platformScript != null)
                {
                    Debug.Log(platformScript.speed);
                }

                grapplePoint = hit.point;

                joint = player.gameObject.AddComponent <SpringJoint>();
                joint.autoConfigureConnectedAnchor = false;
                joint.connectedAnchor = grapplePoint;

                float distanceFromPoint = Vector3.Distance(player.position, grapplePoint);

                // The distance range that tongue will stay between
                joint.maxDistance = distanceFromPoint * 0.4f;
                joint.minDistance = distanceFromPoint * 0.2f;

                // Important properties for feel of grapple
                joint.spring    = 6.0f;
                joint.damper    = 10.0f;
                joint.massScale = 4.5f;

                lr.positionCount      = 2;
                originGrapplePosition = tongueTip.position;
            }
        }
    }