Hi all!
I'm making a game where you try to throw lassos at other players. This requires a lot of spawning a rope, despawning it, then respawning it again.
Currently I do this by disabling the ObiRope and ObiRopeExtrudedRenderer components. When I need it again I reenable it by waiting until the rope is loaded then manually adjust the positions, prevPositions, and Velocities of all particles. Then I wait one frame to let things settle before reenabling the Renderer.
This almost works, except for a single frame where the Renderer shows its previous position. I cannot for the life of me figure out how to make the Renderer only show the new position of the rope rather than starting at its previous position. This also happens when I just leave the Renderer on the entire time.
Is there a better way to go about disabling/enabling rope or some kind of RendererRefresh I can call? I was considering teleporting the rope somewhere far away while disabled rather than disabling the component but wanted to see if there was a better way first.
Thanks!
Pic of the one frame issue:
![[Image: T5Tm5FC.png]](https://i.imgur.com/T5Tm5FC.png)
I'm making a game where you try to throw lassos at other players. This requires a lot of spawning a rope, despawning it, then respawning it again.
Currently I do this by disabling the ObiRope and ObiRopeExtrudedRenderer components. When I need it again I reenable it by waiting until the rope is loaded then manually adjust the positions, prevPositions, and Velocities of all particles. Then I wait one frame to let things settle before reenabling the Renderer.
This almost works, except for a single frame where the Renderer shows its previous position. I cannot for the life of me figure out how to make the Renderer only show the new position of the rope rather than starting at its previous position. This also happens when I just leave the Renderer on the entire time.
Is there a better way to go about disabling/enabling rope or some kind of RendererRefresh I can call? I was considering teleporting the rope somewhere far away while disabled rather than disabling the component but wanted to see if there was a better way first.
Thanks!
Pic of the one frame issue:
![[Image: T5Tm5FC.png]](https://i.imgur.com/T5Tm5FC.png)
Code:
// sets up the rope when reenabled
private IEnumerator SetupRopeNextFrame(Transform startTarget, bool isStartDynamicAttachment, Transform endTarget, bool isEndDynamicAttachment)
{
while(!rope.isLoaded)
{
yield return null;
}
resetRopeLength();
connectToBothTargets(startTarget, isStartDynamicAttachment, endTarget, isEndDynamicAttachment); //calls connectParticleToTarget() and lerpBetweenStartAndEndOfRope()
_ropeIsActive = true;
yield return null;
ropeRenderer.enabled = true;
}
// creates world peace
public void DeactivateRope()
{
_ropeIsActive = false;
startAttachment.enabled = false;
endAttachment.enabled = false;
rope.enabled = false;
_isRetracting = false;
ropeRenderer.enabled = false;
}
// connects the ends to attachments
private void connectParticleToTarget(int particleIndex, Transform target)
{
Vector3 newPos = rope.solver.transform.InverseTransformPoint(target.position + new Vector3(0f, -.5f, 0f));
rope.solver.positions[particleIndex] = newPos;
rope.solver.prevPositions[particleIndex] = newPos;
rope.solver.velocities[particleIndex] = Vector3.zero;
}
// handles mid section of the rope
private void lerpBetweenStartAndEndOfRope(Transform startTarget, Transform endTarget)
{
//start at 1 because both start and end are already in position
int edgeCount = rope.elements.Count;
for(int i = 1; i < edgeCount - 1; i++)
{
int index = rope.elements[i].particle1;
float percent = (float) i / edgeCount;
Vector3 worldPos = Vector3.Lerp(startTarget.position, endTarget.position, percent);
Vector3 localPos = rope.solver.transform.InverseTransformPoint(worldPos);
rope.solver.positions[index] = localPos;
rope.solver.prevPositions[index] = localPos;
rope.solver.velocities[index] = Vector4.zero;
}
}

