예제 #1
0
    void Start()
    {
        if (!endObject)
        {
            return;
        }

        Destroy(collider);

        if (gameObject.GetComponent <Renderer> ())
        {
            gameObject.GetComponent <Renderer> ().enabled = false;
        }

        Destroy(endObject.collider);

        if (endObject.gameObject.GetComponent <Renderer> ())
        {
            endObject.gameObject.GetComponent <Renderer> ().enabled = false;
        }

        numKnots = (int)(Vector3.Distance(transform.position, endObject.position) * resoloution);

        Debug.Log(endObject.position);

        float springLength = Vector3.Distance(transform.position, endObject.position) / (float)(numKnots - 1);

        float knotMass = mass / (float)numKnots;



        knots = new GameObject[numKnots];

        springs = new RopeSpring[numKnots - 1];



        for (int i = 0; i < numKnots; i++)
        {
            GameObject knot = GameObject.CreatePrimitive(PrimitiveType.Sphere);

            knot.name = "Knot-" + i + "-" + gameObject.name;

            //knot.transform.parent=transform;

            knot.transform.localScale = Vector3.one * radius * 2;

            knot.AddComponent <Rigidbody> ();

            knot.rigidbody.mass = knotMass;

            if (i == 0 && lockStart)
            {
                knot.rigidbody.isKinematic = true;
            }

            if (i == numKnots - 1 && lockEnd)
            {
                knot.rigidbody.isKinematic = true;
            }

            knot.transform.position = Vector3.Lerp(transform.position, endObject.position, (float)i / (float)(numKnots - 1));

            knots [i] = knot;
        }

        //knots[0].transform.parent=transform;



        for (int i = 0; i < numKnots - 1; i++)
        {
            springs [i] = new RopeSpring(knots [i], knots [i + 1],

                                         springConstant, springLength, springFrictionConstant);
        }
    }
	void Start ()
	{

		if (! endObject)
			return;

		Destroy (collider);

		if (gameObject.GetComponent<Renderer> ())
			gameObject.GetComponent<Renderer> ().enabled = false;

		Destroy (endObject.collider);

		if (endObject.gameObject.GetComponent<Renderer> ())
			endObject.gameObject.GetComponent<Renderer> ().enabled = false;

		numKnots = (int)(Vector3.Distance (transform.position, endObject.position) * resoloution);

		Debug.Log (endObject.position);

		float springLength = Vector3.Distance (transform.position, endObject.position) / (float)(numKnots - 1);

		float knotMass = mass / (float)numKnots;

        

		knots = new GameObject[numKnots];

		springs = new RopeSpring[numKnots - 1];

        

		for (int i = 0; i < numKnots; i++) {

			GameObject knot = GameObject.CreatePrimitive (PrimitiveType.Sphere);

			knot.name = "Knot-" + i + "-" + gameObject.name;

			//knot.transform.parent=transform;

			knot.transform.localScale = Vector3.one * radius * 2;

			knot.AddComponent<Rigidbody> ();

			knot.rigidbody.mass = knotMass;

			if (i == 0 && lockStart)
				knot.rigidbody.isKinematic = true;

			if (i == numKnots - 1 && lockEnd)
				knot.rigidbody.isKinematic = true;

			knot.transform.position = Vector3.Lerp (transform.position, endObject.position, (float)i / (float)(numKnots - 1));

			knots [i] = knot;

		}

		//knots[0].transform.parent=transform;

        

		for (int i = 0; i < numKnots - 1; i++) {

			springs [i] = new RopeSpring (knots [i], knots [i + 1], 

                springConstant, springLength, springFrictionConstant);

		}

	}