Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Creating rope between two points at Runtime
#2
Hi there!

There's many things off in your code:

1.- You're rotating the rope's transform so that it aligns to the vector from EndPosition to StartPosition. However, you're inserting control points at EndPosition and StartPosition too. Rope control points are expressed in the rope's local space, so you should either leave the rope's transform intact and place the control points at start/end positions (assuming your start/end data is expressed in world space) or convert them to local space if you want to position/rotate the transform.

2.- Minor detail: you're using InsertControlPoint and passing the last index of the rope. Would be easier to use AddControlPoint(), as it automatically appends a new control point at the end.

3.- You're accessing newRope.blueprint.groups[1] and newRope.blueprint.groups[2] fro the attachments. Array indices in C# are zero-based, so if your rope has 2 control points, there will only be 2 groups: newRope.blueprint.groups[0] and newRope.blueprint.groups[1]. Accessing newRope.blueprint.groups[2] should result in an out of bounds exception.

3.- You're using a cursor to set the rope length to the exact same length it has at rest. This doesn't make much sense, will have no effect on the rope but will slightly affect performance. You can get rid of [code]cursor.ChangeLength(Vector3.Magnitude(StartPosition - EndPosition));
Reply


Messages In This Thread
RE: Creating rope between two points at Runtime - by josemendez - 18-06-2021, 08:17 AM