Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Runtime Adding/Changing Control Points
#1
I am trying to add new control points to the Obi Rope in runtime using the same method shown in the docs, so that by using a Linecast line of sight I can identify points which the rope could lay through with enough length, and update that real time as the player moves through the level.

https://gyazo.com/12e11ed1fd2779065ce15c923196efef

This is what happens when I try to add a control point in the middle of the rope, and I cant figure out what in particular is going wrong. Heres the code:

Code:
Vector3 example, tangentLS = new Vector3(0, 0, 0);
example = (startPoint.position + endPoint.position) / 2 + Vector3.up - transform.position;
tangentLS = (endPoint.position - startPoint.position).normalized;
path.InsertControlPoint(1, example, -tangentLS, tangentLS, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "test");
path.FlushEvents();

I also can't find in the API of how to change the position of any control Point in runtime, which I think I need to know for the Cursor Mu and ChangeLength to behave correctly.

Any help is appreciated, thanks.
Reply
#2
(26-07-2021, 04:21 AM)Aolifu Wrote: I am trying to add new control points to the Obi Rope in runtime using the same method shown in the docs, so that by using a Linecast line of sight I can identify points which the rope could lay through with enough length, and update that real time as the player moves through the level.

Adding points to the blueprint requires re-generating the rope from scratch, so this would reset the rope to its rest shape anytime you modify the blueprint. Control points are only used to work with blueprints, particles are used to work with actors. So unless you're ok with re-generating the rope during the game, you should work with particles instead.

https://gyazo.com/12e11ed1fd2779065ce15c923196efef

(26-07-2021, 04:21 AM)Aolifu Wrote: This is what happens when I try to add a control point in the middle of the rope, and I cant figure out what in particular is going wrong. Heres the code:

Point data (like all actor data) is expected in local space. You're passing data in world space, hence the problem. Convert your positions (startPoint.position and endPoint.position) to local space before passing them to InsertControlPoint().

Quote:I also can't find in the API of how to change the position of any control Point in runtime, which I think I need to know for the Cursor Mu and ChangeLength to behave correctly.

Control points are only used to generate a rope's blueprint, which determines its rest configuration/shape. At runtime they are not used, as the rope is represented using particles. Generating particles from a blueprint is a one-way operation, once the blueprint's been used to create a rope, the rope simulation no longer uses the blueprint. So you don't need to know or do anything about control points to work with cursors. They're completely unrelated.

The CursorMu is a normalized value in the 0-1 range, representing a position along the rope. A value of 0 means the start of the rope, a value of 1 means its end. ChangeLength() sets the rest length of the rope by automatically adding/removing particles and constraints. You can get the rope's current rest length like this:

Code:
float length = rope.restLength;

This being said, you can change the position of existing control points just by accessing them in the path. Keep in mind control points are structs, so you must modify a copy and then set it back like so:

Code:
var point = path.points[index];
point.position = Vector3.zero;
path.points[index] = point;
Reply