Home Game Development unity – OBI Rope, Create a curve from listing of Vector3 factors

unity – OBI Rope, Create a curve from listing of Vector3 factors

0
unity – OBI Rope, Create a curve from listing of Vector3 factors

[ad_1]

I’m utilizing a Unity Plugin Obi Rope to create rope-based mechanics.
I’m engaged on creating an obi rope curve via code and rendering rope on that curve.
I’m caught in the intervening time the place I can spawn factors of the curve within the right place however tangents are disturbed on account of which the curve is irregular(as proven within the screenshot).
enter image description here
Following code focuses on producing curve for rope:

Vector3 tangentLS = default;
        for (int i = 0; i < ropeSaveData.ropeCurvePoints.Count; i++)
        {
            // Calculate management level positions and tangent vector:
            Vector3 currentPointPosition =
                generatedRope.remodel.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i]);
            if (i == 0)
            {
                Vector3 nextPointPosition =
                    generatedRope.remodel.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
                tangentLS = (nextPointPosition - currentPointPosition).normalized;
            }
            else if (i < ropeSaveData.ropeCurvePoints.Count - 1)
            {
                Vector3 previousPointPosition =
                    generatedRope.remodel.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i - 1]);
                Vector3 nextPointPosition =
                    generatedRope.remodel.InverseTransformPoint(ropeSaveData.ropeCurvePoints[i + 1]);
                tangentLS = (nextPointPosition - previousPointPosition).normalized;
            }

            // Build the rope path:
            blueprint.path.AddControlPoint(currentPointPosition, -tangentLS, tangentLS, Vector3.up,
                0.1f, 0.1f, 1, filter, Color.white, "start_" + i);
        }

So primarily AddControlPoint is liable for creating curve for obi rope.

Following is the strategy signature:

public void AddControlPoint(Vector3 place, Vector3 inTangentVector, Vector3 outTangentVector, Vector3 regular, float mass, float rotationalMass, float thickness, int filter, Color shade, string identify)

Additional info round this. I attempted this with 2 factors(vector3) and following code works completely nice since this curve is only a line however the above one shouldn’t be a straight line it is a listing of vector3 factors.

 // Calculate management level positions and tangent vector:
        Vector3 startPositionLS = generatedRope.remodel.InverseTransformPoint(begin.place);
        Vector3 endPositionLS = generatedRope.remodel.InverseTransformPoint(finish.place);
        Vector3 tangentLS = (endPositionLS - startPositionLS).normalized;

        // Create the blueprint: 
        var blueprint = ScriptableObject.CreateOccasion<ObiRopeBlueprint>();
        blueprint.decision = 0.5f;
        // Build the rope path:
        int filter = ObiUtils.MakeFilter(ObiUtils.CollideWithEverything, 0);
        blueprint.path.AddControlPoint(startPositionLS, -tangentLS, tangentLS, Vector3.up, 0.1f, 0.1f, 1,
            filter, Color.white, "begin");
        blueprint.path.AddControlPoint(endPositionLS, -tangentLS, tangentLS, Vector3.up, 0.1f, 0.1f, 1, filter,
            Color.white, "finish");

Helping word for readers right here which can be prepared to assist:

Tangent size impacts the curvature of the trail, simply line in any
spline. Depending on how far-off from one another your factors are,
utilizing normalized tangents (with size 1) could also be an excessive amount of and the trail
can have a bizarre form. Try lowering the size of the tangents,
proportionally to the gap between factors.

This is one thing which is beneficial however I’m unable to really remodel this right into a code.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here