14-07-2017, 07:02 PM
(10-07-2017, 01:56 PM)PhantomBadger Wrote: Tangentially related to my previous thread (here), but ultimately a different issue, so I decided to make a new topic;
Is there a way to teleport the rope, essentially 'resetting' it at a new position during runtime?
I mentioned my current set up in the previous thread (this post), where the rope object is connected to two anchors, which are then connected to two external game objects. My current attempt teleport all these components, the anchors and game objects teleport fine, but the rope then flies towards them to catch up, causing high velocities and undesired effects.
Cheers!
EDIT:
Seems I was a bit quick to post here! The solution I found was calling the aptly named 'ResetActor()' method in ObiRope.
Should anyone else want it, my implemented solution is as follows;
I'm hoping there's no negative repercussions to using this method I'm unaware of?Code:/// <summary>
/// Moves all components of the rope by a set amount
/// </summary>
/// <param name="distanceToMove">The distance to move the rope parts</param>
public void MoveRopeByAmount(Vector3 distanceToMove)
{
//Wire points are the anchor objects
//Target points are the connector gameobjects attached to the anchors
for (int i = 0; i < targetPoints.Length && i < wirePoints.Length; i++)
{
targetPoints[i].transform.position += distanceToMove;
wirePoints[i].transform.position += distanceToMove;
}
ObiRope.transform.position += distanceToMove;
ObiRope.ResetActor();
//Custom method to reset velocity of the rope & it's components
ResetVelocity();
}
If you just want to re-start the simulation when moving the rope, this is fine.
There's however the possibility of doing this: just disable the rope, move it to a new place, yield WaitForFixedUpdate() (so that Obi has time to recognize that you moved the rope!), and re-enable it . Simpler, and you simulation won´t be reset upon teleportation.