void Start()
    {
        #if UNITY_EDITOR
        if (target != null)
        {
            SetTarget(target);
        }
        #endif

        spring = GetComponent <SpringJoint>();

        // Next line ensures that the rigidbody will never sleep, avoiding anchor lock bug
        spring.GetComponent <Rigidbody>().sleepThreshold = 0;
    }
    void OnTriggerDown(GameObject o)
    {
        if (inside == true)
        {
            //rint("YA");
            sj = gameObject.AddComponent <SpringJoint>() as SpringJoint;
            sj.connectedBody = colInside.GetComponent <Rigidbody>();
            sj.anchor        = new Vector3(0, -1, 1);

            sj1 = gameObject.AddComponent <SpringJoint>() as SpringJoint;
            sj1.connectedBody = colInside.GetComponent <Rigidbody>();
            sj1.anchor        = new Vector3(0, 1, 1);
        }
    }
Exemple #3
0
    // Openable behavior
    // destroys spring that existed between controller and this object
    private void UnattachOpenableToController()
    {
        if (openJoint == null)
        {
            Debug.LogError(this.gameObject + " did not have an openJoint, but it should have had one.");
            return;
        }

//        Debug.Log(this.gameObject + " is unpairing with " + currentInteractor.gameObject + " by destroying spring " + openJoint + " on frame " + Time.frameCount);


        Destroy(openJoint);
        openJoint = null;
    }
Exemple #4
0
 private void Awake()
 {
     if (staticDDOL == null)
     {
         staticDDOL = this;
         DontDestroyOnLoad(this);
         joint = GetComponent <SpringJoint>();
     }
     else
     {
         Destroy(this.gameObject);
     }
     this.gameObject.SetActive(false);
 }
Exemple #5
0
 // Helper function to add the spring joints between two pieces
 private void AddSpringConnections(GameObject from, Rigidbody to)
 {
     // Two joints are added for the left and right side
     for (int i = 0; i < 2; ++i)
     {
         SpringJoint joint = from.AddComponent <SpringJoint>();
         joint.autoConfigureConnectedAnchor = false;
         joint.anchor          = new Vector3(-0.5f + (float)(i), 0.5f, 0.5f);
         joint.connectedAnchor = new Vector3(-0.5f + (float)(i), 0.5f, -0.5f);
         joint.connectedBody   = to;
         joint.spring          = _spring;
         joint.breakForce      = _breakForce;
     }
 }
Exemple #6
0
    public void exitLinkingMode()
    {
        Debug.Log("Exiting linking mode");
        shouldHighlightLinks = false;

        // Get list of all colliding elements
        BoxCollider boxCollider = GetComponent <BoxCollider> ();

        Collider[] hitColliders = Physics.OverlapSphere(transform.position, boxCollider.size.x / 2);
        foreach (Collider col in hitColliders)
        {
            GameObject other = col.gameObject;
            if (other == gameObject)
            {
                continue;
            }
            if (other.GetComponent <BoxCollider>() == null)
            {
                continue;
            }
            if (boxCollider.bounds.Intersects(other.GetComponent <BoxCollider>().bounds))
            {
                Debug.Log("Overlapping element" + other);
                //Instantiate(smallCube, this.transform.position, this.transform.rotation);
                // TODO: on release, add a repulsive force between the objects -- or just use spring??

                // then add a spring that acts as a rigid rod to keep them tied together
                SpringJoint newSpring = this.transform.gameObject.AddComponent <SpringJoint> ();
                Debug.Log(other.name);
                newSpring.anchor = Vector3.zero;
                newSpring.autoConfigureConnectedAnchor = false;
                newSpring.connectedAnchor = Vector3.zero;
                newSpring.connectedBody   = other.GetComponent <Rigidbody> ();
                newSpring.minDistance     = 0.5f;
                newSpring.maxDistance     = 0.8f;
                newSpring.spring          = 100f;

                // making a new connection
                if (!links.ContainsKey(other))
                {
                    AddConnection(other);
                    other.GetComponent <CubeStart>().AddConnection(this.gameObject);
                }

                // TODO: also add a visible line that always connects the centers. the connection code is in
                // the line object's script
            }
        }
        //currentCollidingElement = null;
    }
Exemple #7
0
    void Start()
    {
        springJoint = whatTheRopeIsConnectedTo.GetComponent <SpringJoint>();

        //Init the line renderer we use to display the rope
        lineRenderer = GetComponent <LineRenderer>();

        //Init the spring we use to approximate the rope from point a to b
        UpdateSpring();

        //Add the weight to what the rope is carrying
        whatIsHangingFromTheRope.GetComponent <Rigidbody>().mass = loadMass;
        //whatIsHangingFromTheRope.GetComponent<Rigidbody>().drag = drag;
    }
Exemple #8
0
 // Update is called once per frame
 void Update()
 {
     if (interactable && Input.GetKeyDown(KeyCode.E) && player.GetComponent <SpringJoint>() == null)
     {
         objectToActivate.isKinematic = false;
         SpringJoint spring = player.AddComponent <SpringJoint>();
         spring.spring        = 1500f;
         spring.connectedBody = objectToActivate;
     }
     if (Input.GetKeyDown(KeyCode.Q) && player.GetComponent <SpringJoint>() != null)
     {
         Destroy(player.GetComponent <SpringJoint>());
     }
 }
Exemple #9
0
    private void Start()
    {
        rb = GetComponent <Rigidbody>();

        // Get the force that is holding the player upright
        SpringJoint joint = GetComponent <SpringJoint>();
        Rigidbody   connectedComponent = joint.connectedBody;

        objectForce = connectedComponent.GetComponent <ConstantForce>();

        // Get the maximum y force that we can apply to the body to keep it upright
        maxYForce = objectForce.force.y;
        gameMode  = transform.parent.parent.parent.parent.gameObject.GetComponent <GlobalScore>();
    }
Exemple #10
0
    public void SetParent(Node parent)
    {
        this.m_Parent = parent;
        // create a pulling force between this child and its parent
        SpringJoint spring = this.gameObject.AddComponent <SpringJoint>();

        spring.anchor        = new Vector3();
        spring.connectedBody = parent.GetRigidBody();
        spring.damper        = 1000;
        spring.tolerance     = 2f;

        // parents with more children "weigh" more so they don't get pulled around as much
        this.GetRigidBody().mass += 10.0f;
    }
Exemple #11
0
    void Start()
    {
        source = GetComponent <AudioSource>();

        hookBody        = GetComponent <Rigidbody>();
        ropeEffect      = player.GetComponent <SpringJoint>();
        playerRigidBody = player.GetComponent <Rigidbody>();
        launchRope      = true;
        ropeCollided    = false;

        lrRope = GetComponent <LineRenderer>();
        lrRope.SetWidth(0.05f, 0.05f);
        lrRope.SetColors(Color.blue, Color.blue);
    }
Exemple #12
0
    private void AddAndConfigureSpringJoint(Rigidbody iObjectRb)
    {
        iObjectRb.useGravity = false;
        SpringJoint            AddedSpringJoint = iObjectRb.gameObject.AddComponent <SpringJoint>();
        LookUpTableSpringJoint objectSpringJointCaracteristics = iObjectRb.GetComponent <LookUpTableSpringJoint>();

        AddedSpringJoint.connectedBody = rb;
        AddedSpringJoint.anchor        = Vector3.zero;
        AddedSpringJoint.autoConfigureConnectedAnchor = false;
        AddedSpringJoint.connectedAnchor = Vector3.zero;

        AddedSpringJoint.spring = objectSpringJointCaracteristics.StrengthJoint;
        AddedSpringJoint.damper = objectSpringJointCaracteristics.SpringDamping;
    }
Exemple #13
0
    void Update()
    {
        // Make sure the user pressed the mouse down
        if (!Input.GetMouseButtonDown(0))
        {
            return;
        }

        var mainCamera = FindCamera();

        // We need to actually hit an object
        RaycastHit hit;

        if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit, 100))
        {
            return;
        }
        // We need to hit a rigidbody that is not kinematic
        if (!hit.rigidbody || hit.rigidbody.isKinematic)
        {
            return;
        }

        if (!springJoint)
        {
            GameObject go   = new GameObject("Rigidbody dragger");
            Rigidbody  body = go.AddComponent <Rigidbody>();    // ("Rigidbody");
            springJoint      = go.AddComponent <SpringJoint>(); // ("SpringJoint");
            body.isKinematic = true;
        }

        springJoint.transform.position = hit.point;
        if (attachToCenterOfMass)
        {
            Vector3 anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position;
            anchor             = springJoint.transform.InverseTransformPoint(anchor);
            springJoint.anchor = anchor;
        }
        else
        {
            springJoint.anchor = Vector3.zero;
        }

        springJoint.spring        = spring;
        springJoint.damper        = damper;
        springJoint.maxDistance   = distance;
        springJoint.connectedBody = hit.rigidbody;

        StartCoroutine("DragObject", hit.distance);
    }
Exemple #14
0
    public caterpillarJoint(Vector3 position, int tailSegments)
    {
        head = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        head.transform.localPosition = position;

        head.transform.localScale = new Vector3(2f, 2f, 2f);

        //We need to create a new material for WebGL
        Renderer r = head.GetComponent <Renderer>();

        r.material       = new Material(Shader.Find("Diffuse"));
        r.material.color = Color.blue;

        headRb      = head.AddComponent <Rigidbody>();
        headRb.mass = 100f;

        for (int i = 0; i < tailSegments; i++)
        {
            GameObject tail = GameObject.CreatePrimitive(PrimitiveType.Cube);
            tail.transform.localScale    = new Vector3(1f, 1f, 1f);
            tail.transform.localPosition = new Vector3(position.x - head.transform.localScale.x, 0f, position.z);

            //We need to create a new material for WebGL
            Renderer t = tail.GetComponent <Renderer>();
            t.material       = new Material(Shader.Find("Diffuse"));
            t.material.color = Color.red;

            Rigidbody   tailRb          = tail.AddComponent <Rigidbody>();
            SpringJoint tailSpringJoint = tail.AddComponent <SpringJoint>();
            tailRbs.Add(tailRb);

            tailSpringJoint.autoConfigureConnectedAnchor = false;

            tailSpringJoint.anchor          = new Vector3(.5f, 0f, 0f);
            tailSpringJoint.connectedAnchor = new Vector3(-.5f, 0f, 0f);

            tailSpringJoint.minDistance = .001f;
            tailSpringJoint.maxDistance = .001f;

            //Connect to the head if it is the last tail segment, otherwise add to the previous rb
            if (i == 0)
            {
                tailSpringJoint.connectedBody = headRb;
            }
            else if (i < tailSegments)
            {
                tailSpringJoint.connectedBody = tailRbs[i - 1];
            }
        }
    }
Exemple #15
0
        private void Update()
        {
            // Make sure the user pressed the mouse down
            if (!Input.GetMouseButtonDown(0))
            {
                return;
            }

            var mainCamera = FindCamera();

            // We need to actually hit an object
            RaycastHit hit       = new RaycastHit();
            int        layerMask = 1 << 8;

            layerMask = ~layerMask;
            if (
                !Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition).origin,
                                 mainCamera.ScreenPointToRay(Input.mousePosition).direction, out hit, 100,
                                 layerMask))
            {
                return;
            }
            if (!hit.transform.GetComponent <ObjectProperties>().GetCanHold())
            {
                return;
            }
            // We need to hit a rigidbody that is not kinematic
            if (!hit.rigidbody || hit.rigidbody.isKinematic)
            {
                return;
            }

            if (!m_SpringJoint)
            {
                var       go   = new GameObject("Rigidbody dragger");
                Rigidbody body = go.AddComponent <Rigidbody>();
                m_SpringJoint    = go.AddComponent <SpringJoint>();
                body.isKinematic = true;
            }

            m_SpringJoint.transform.position = hit.point;
            m_SpringJoint.anchor             = Vector3.zero;

            m_SpringJoint.spring        = k_Spring;
            m_SpringJoint.damper        = k_Damper;
            m_SpringJoint.maxDistance   = k_Distance;
            m_SpringJoint.connectedBody = hit.rigidbody;

            StartCoroutine("DragObject", hit.distance);
        }
Exemple #16
0
    private void CreateSpring(int idx1, int idx2, float springForce, float damperForce)
    {
        Rigidbody   rigidbody   = bodies[idx1];
        Rigidbody   rigidbody2  = bodies[idx2];
        SpringJoint springJoint = rigidbody.gameObject.AddComponent <SpringJoint>();

        springJoint.autoConfigureConnectedAnchor = false;
        springJoint.connectedBody = rigidbody2;
        Vector3 vector2 = springJoint.anchor = (springJoint.connectedAnchor = Vector3.zero);
        float   num2    = springJoint.minDistance = (springJoint.maxDistance = (rigidbody.position - rigidbody2.position).magnitude);

        springJoint.spring = springForce;
        springJoint.damper = damperForce;
    }
    void Update()
    {
        if (!Input.GetMouseButtonDown(0))
        {
            return;
        }

        Camera mainCamera = FindCamera();

        RaycastHit hit;

        if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit, maxDistance))
        {
            return;
        }
        if (!hit.rigidbody || hit.rigidbody.isKinematic)
        {
            return;
        }

        if (!springJoint)
        {
            GameObject go   = new GameObject("Rigidbody dragger");
            Rigidbody  body = go.AddComponent <Rigidbody>();
            body.isKinematic = true;
            springJoint      = go.AddComponent <SpringJoint>();

            //added to peg game
            initialPosition = myTransform.position;
        }

        springJoint.transform.position = hit.point;
        if (attachToCenterOfMass)
        {
            Vector3 anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position;
            anchor             = springJoint.transform.InverseTransformPoint(anchor);
            springJoint.anchor = anchor;
        }
        else
        {
            springJoint.anchor = Vector3.zero;
        }

        springJoint.spring        = spring;
        springJoint.damper        = damper;
        springJoint.maxDistance   = distance;
        springJoint.connectedBody = hit.rigidbody;

        StartCoroutine(DragObject(hit.distance));
    }
    public void AddEdge(Node n)
    {
        SpringJoint sj = gameObject.AddComponent <SpringJoint> ();

        sj.autoConfigureConnectedAnchor = false;
        sj.anchor          = new Vector3(0, 0.5f, 0);
        sj.connectedAnchor = new Vector3(0, 0, 0);
        sj.enableCollision = true;
        sj.connectedBody   = n.GetComponent <Rigidbody>();
        GameObject edge = Instantiate(this.epf, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity);

        edges.Add(edge);
        joints.Add(sj);
    }
Exemple #19
0
    private void SpringRope()
    {
        int layerMask1 = 1 << 8;
        int layerMask2 = 1 << 2;
        int finalMask  = layerMask1 | layerMask2;

        finalMask = ~finalMask;

        RaycastHit hit;
        Ray        ray = mainCamera.ScreenPointToRay(Input.mousePosition);

        // TODO Make the rope move with the object it hit/disconnect when it disapperars
        if (Physics.Raycast(mainCamera.transform.position, mainCamera.transform.forward, out hit, 100, finalMask) && Input.GetButtonDown("Fire1"))
        {
            ropePoint = hit.point;
            SpringJoint spring = player.AddComponent <SpringJoint>();
            spring.anchor = ropeOriginPoint.transform.localPosition;
            spring.autoConfigureConnectedAnchor = false;
            spring.connectedAnchor = hit.point;
            spring.spring          = ropeStiffness;

            float distanceFromPoint = Vector3.Distance(player.transform.position, hit.point);
            maxDistance  = distanceFromPoint;
            ropeEndPoint = hit.point;
            ropeEnabled  = true;

            spring.maxDistance = distanceFromPoint;
            spring.minDistance = distanceFromPoint * 0.15f;

            spring.damper = 7f;

            targetTransform = hit.transform;
        }

        if (targetTransform != null)
        {
        }
        if (Input.GetButton("Fire2") && player.GetComponent <SpringJoint>() != null)
        {
            RetractRope();
        }
        if (Input.GetButtonUp("Fire1"))
        {
            ropeEnabled     = false;
            targetTransform = null;
            StartCoroutine(LineFade());
            Destroy(player.GetComponent <SpringJoint>());
        }
    }
Exemple #20
0
    protected override IEnumerator PerformAction()
    {
        // randomly select 2 units in the bind area
        float adjBindRadius = bindRadius * actor.AbilityRangeMultiplier.Current;

        Collider[]  colliders = Physics.OverlapSphere(castPoint, adjBindRadius);
        List <Unit> units     = new List <Collider>(colliders).ConvertAll <Unit>(c => c.GetComponentInParent <Unit>()).FindAll(u => u != null && u.Health.IsAlive);

        // TODO: shuffle
        if (units.Count > 2)
        {
            units.RemoveRange(2, units.Count - 2);
        }
        else if (units.Count < 2)
        {
            Debug.Log("Not enough targets to tether");
            yield break;
        }

        // bind the 2 units together
        List <Rigidbody> rbs         = units.ConvertAll <Rigidbody>(u => u.GetComponent <Rigidbody>());
        SpringJoint      springJoint = rbs[0].gameObject.AddComponent <SpringJoint>();

        springJoint.autoConfigureConnectedAnchor = false;
        springJoint.connectedBody   = rbs[1];
        springJoint.connectedAnchor = Vector3.zero;
        springJoint.spring          = 2;
        springJoint.enableCollision = true;

        // add a visual effect
        ParticleSystem vfx = Instantiate <ParticleSystem>(vfxPrefab);

        float time = 0;

        while (time < duration)
        {
            vfx.transform.position = units[0].ChestTransform.position;
            vfx.transform.LookAt(units[1].ChestTransform);
            yield return(new WaitForEndOfFrame());

            time += Time.deltaTime;
        }

        // tether ended, clean up
        Destroy(vfx.gameObject);
        Destroy(springJoint);

        yield break;
    }
Exemple #21
0
    void Update()
    {
        // Make sure the user pressed the mouse down
        if (!Input.GetKeyDown(FPSPlayerComponent.moveObject))
        {
            return;
        }

        // We need to actually hit an object
        RaycastHit hit;

        if (!Physics.Raycast(mainCamTransform.position, ((mainCamTransform.position + mainCamTransform.forward * reachDistanceAmt) - mainCamTransform.position).normalized, out hit, reachDistanceAmt, layersToDrag))
        {
            return;
        }
        // We need to hit a rigidbody that is not kinematic
        if (!hit.rigidbody || hit.rigidbody.isKinematic)
        {
            return;
        }

        if (!springJoint)
        {
            GameObject go   = new GameObject("Rigidbody dragger");
            Rigidbody  body = go.AddComponent("Rigidbody") as Rigidbody;
            springJoint      = go.AddComponent("SpringJoint") as SpringJoint;
            body.isKinematic = true;
        }

        springJoint.connectedBody      = hit.rigidbody;
        springJoint.transform.position = hit.point;

        if (attachToCenterOfMass)
        {
            Vector3 anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position;
            anchor             = springJoint.transform.InverseTransformPoint(anchor);
            springJoint.anchor = anchor;
        }
        else
        {
            springJoint.anchor = Vector3.zero;
        }

        springJoint.spring      = spring;
        springJoint.damper      = damper;
        springJoint.maxDistance = distance;

        StartCoroutine("DragObject", hit.distance);
    }
Exemple #22
0
    /// <summary>
    /// Call whenever we want to start a grapple
    /// </summary>
    void StartGrapple()
    {
        RaycastHit hit;

        //if (Physics.Raycast(camera.position, camera.forward, out hit, maxDistance, whatIsGrappleable))
        if (Physics.SphereCast(camera.position, sphereCastRadius, camera.forward, out hit, maxDistance, whatIsGrappleable))
        {
            joint = player.gameObject.AddComponent <SpringJoint>();
            joint.autoConfigureConnectedAnchor = false;

            if (hit.transform.gameObject.GetComponent <Grappable>() != null)
            {
                joint.connectedBody      = hit.rigidbody;
                joint.connectedMassScale = 100;
                grappleAnchor            = hit.transform.gameObject.GetComponent <Grappable>().CreateJointAnchor(hit);
                grapplePoint             = grappleAnchor.transform.localPosition;
            }
            else
            {
                grapplePoint = hit.point;
            }
            joint.connectedAnchor = grapplePoint;


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

            //The distance grapple will try to keep from grapple point.
            joint.maxDistance = distanceFromPoint * 0.8f;
            joint.minDistance = 0.25f;

            //Set desiredLenght for pulling function to "default value" of start max joint distance
            //Set pull speed to default pull speed
            print("Previous pull speed: " + currentPullSpeed);
            currentPullSpeed = joint.maxDistance * 0.01f * defaultPullSpeed;
            print("Set pulling parameters to default: " + currentPullSpeed);
            print("Start max distance: " + joint.maxDistance);
            print("Start min distance: " + joint.minDistance);
            print("Start connected mass scale: " + joint.connectedMassScale);


            //Adjust these values to fit your game.
            joint.spring    = jointSpring;
            joint.damper    = jointDamper;
            joint.massScale = jointMassScale;

            lr.positionCount       = 2;
            currentGrapplePosition = gunTip.position;
        }
    }
Exemple #23
0
    void SetSpringJoint(SpringJoint springJoint, GameObject connectedGameObject)
    {
        springJoint.connectedBody = connectedGameObject.GetComponent <Rigidbody>();
        SpringJoint prefab = springJoint.gameObject == gameObject ? rootJointPrefab : childJointPrefab;

        springJoint.anchor = prefab.anchor;
        springJoint.autoConfigureConnectedAnchor = prefab.autoConfigureConnectedAnchor;

        var sbc = springJoint.GetComponent <BoxCollider>();

        if (sbc)
        {
            Vector3 anchor = sbc.size / 2;
            anchor.y           = 0;
            anchor.z           = 0;
            springJoint.anchor = anchor;
        }

        var cbc = connectedGameObject.GetComponent <BoxCollider>();

        if (cbc)
        {
            springJoint.autoConfigureConnectedAnchor = false;
            Vector3 anchor = cbc.size / 2;
            anchor.y = 0;
            anchor.z = 0;
            anchor.x = -anchor.x;
            springJoint.connectedAnchor = anchor;
        }

        springJoint.spring      = prefab.spring;
        springJoint.damper      = prefab.damper;
        springJoint.minDistance = prefab.minDistance;
        springJoint.maxDistance = prefab.maxDistance;
        springJoint.tolerance   = prefab.tolerance;
        if (springJoint.gameObject != gameObject)
        {
            springJoint.breakForce = prefab.breakForce * Mathf.Sqrt(Mathf.Sqrt(1f / nodeList.Count));
        }
        else
        {
            springJoint.breakForce = prefab.breakForce;
        }
        springJoint.breakTorque         = prefab.breakTorque;
        springJoint.enableCollision     = prefab.enableCollision;
        springJoint.enablePreprocessing = prefab.enablePreprocessing;
        springJoint.massScale           = prefab.massScale;
        springJoint.connectedMassScale  = prefab.connectedMassScale;
    }
Exemple #24
0
    void Update()
    {
        if (GetBody() != null)
        {
            SpringJoint bounce = robot_body_.feet.GetComponent <SpringJoint>();

            float progress    = (1.0f * beatSource.timeSamples) / beatSource.clip.samples;
            float dance_phase = dancesPerLoop * progress;
            dance_phase -= (int)dance_phase;

            if (dance_phase < danceDutyCycle && GetBody().feet.IsUpright())
            {
                bounce.connectedAnchor = (1 - danceScale) * resting_anchor_;
            }
            else
            {
                bounce.connectedAnchor = resting_anchor_;
            }

            if (GetBody().feet.IsUpright())
            {
                int        head_mask = LayerMask.GetMask("BoxHead");
                Collider[] heads     = Physics.OverlapSphere(transform.position, loverRadius, head_mask);
                Transform  chaser    = null;
                foreach (Collider head in heads)
                {
                    RobotHead lovey_head = head.GetComponent <RobotLoveyHead>();
                    if (lovey_head != null && lovey_head.GetBody() != null)
                    {
                        chaser = head.transform;
                    }
                }

                if (chaser != null)
                {
                    RunAway(chaser);
                    if (!running_)
                    {
                        SetEyes(leftScaredEye, rightScaredEye);
                    }
                }
                else if (running_)
                {
                    SetEyes(leftHappyEye, rightHappyEye);
                }
                running_ = chaser != null;
            }
        }
    }
    void ReleaseObject()
    {
        if (joint_f != null)
        {
            //destroy the joint between the Controller and the grabbedObject
            Object.DestroyImmediate(joint_f);
            //clear the joint
            joint_f = null;

            //if the parent object's parent is the world
            if (grabbedObject.GetComponent <VRBasics_Grabbable> ().GetOriginalParent() == null)
            {
                if (grabbedObject.transform.parent != null)
                {
                    grabbedObject.transform.parent = null;
                }
            }
            else
            {
                if (grabbedObject.transform.parent != grabbedObject.GetComponent <VRBasics_Grabbable> ().GetOriginalParent().transform)
                {
                    grabbedObject.transform.parent = grabbedObject.GetComponent <VRBasics_Grabbable> ().GetOriginalParent().transform;
                }
            }
        }

        if (joint_s != null)
        {
            //destroy the joint between the Controller and the grabbedObject
            Object.DestroyImmediate(joint_s);
            //clear the joint
            joint_s = null;
        }

        //play the release sound
        if (grabbedObject.GetComponent <VRBasics_Grabbable> ().releasedAudio)
        {
            grabbedObject.GetComponent <VRBasics_Grabbable> ().releasedAudio.Play();
        }

        //THROW
        //check if object is throwable
        if (grabbedObject.GetComponent <VRBasics_Grabbable> ().isThrowable)
        {
            ThrowObject();
        }

        UnGrabObject();
    }
Exemple #26
0
    public void ResetHolding()
    {
        //if (holdingGameObject.GetComponent<Rigidbody>()) holdingGameObject.GetComponent<Rigidbody>().constraints = rigidbodyConstraints;
        if (holdingGameObject.transform.position.z != 0)
        {
            holdingGameObject.transform.position = new Vector3(holdingGameObject.transform.position.x, holdingGameObject.transform.position.y, 0);
        }
        holding           = null;
        holdingGameObject = null;

        if (GetComponent <Jump>())
        {
            GetComponent <Jump>().enabled = true;
        }
    }
Exemple #27
0
    // Use this for initialization
    void Start()
    {
        m_Hook.transform.parent   = null;
        m_Bobber.transform.parent = null;

        m_BobberJoint = m_Bobber.GetComponent <SpringJoint>();

        /*
         * m_HookJoint = m_Hook.GetComponent<SpringJoint>();
         *
         * m_BobberJoint.maxDistance = Vector3.Distance(m_FishingRodTip.transform.position, m_Bobber.transform.position);
         * m_HookJoint.maxDistance = Vector3.Distance(m_Bobber.transform.position, m_Hook.transform.position);
         */
        m_fishingLogic = FindObjectOfType <FishingLogic>();
    }
Exemple #28
0
    void AddDistanceConstraint(GameObject sourceGO, GameObject targetGO, float distance, int springStrength)
    {
        SpringJoint sjDist = sourceGO.AddComponent(typeof(SpringJoint)) as SpringJoint;

        sjDist.connectedBody = targetGO.GetComponent <Rigidbody>();
        sjDist.autoConfigureConnectedAnchor = false;
        sjDist.anchor          = new Vector3(0f, 0f, 0f);
        sjDist.connectedAnchor = new Vector3(0f, 0f, 0f);
        sjDist.spring          = springStrength;
        sjDist.enableCollision = true;
        sjDist.minDistance     = distance;
        sjDist.maxDistance     = distance / 1.2f;
        sjDist.tolerance       = 0f;
        sjDist.tag             = "dist";
    }
Exemple #29
0
    IEnumerator Fixate()
    {
        //source.pitch = Random.Range (0.95f, 1.05f);
        source.Play();
        Camera.main.GetComponent <_17_scr_ScreenShakeGenerator> ().ShakeScreen(0.1f, 0.05f);

        SpringJoint joint = GetComponent <SpringJoint> ();

        joint.breakForce = 0;
        yield return(null);

        rb.isKinematic = true;

        manager.tumblers.Remove(gameObject);
    }
Exemple #30
0
    public void Pickup()
    {
        Connector = this.gameObject.AddComponent(typeof(SpringJoint)) as SpringJoint;       //assign connector info
        Connector.connectedBody = GameObject.FindWithTag("Camera").GetComponent <Rigidbody>();
        Connector.autoConfigureConnectedAnchor = false;
        Connector.connectedAnchor = new Vector3(0f, 0, 0.8f);
        Connector.spring          = 300f;
        Connector.damper          = 0f;
        Connector.minDistance     = 0.0f;
        Connector.maxDistance     = 0.0f;
        Connector.enableCollision = true;

        r.drag = 7f;                                //change drag to make it work
        r.mass = 1f;
    }