24-06-2021, 03:54 PM
Hello I am trying to delete cuted part of the rope with particles but it doesnt work. Can anybody help me?
Help Obi rope deleteingt cutted part after cut?
|
24-06-2021, 03:54 PM
Hello I am trying to delete cuted part of the rope with particles but it doesnt work. Can anybody help me?
24-06-2021, 04:19 PM
24-06-2021, 04:39 PM
(24-06-2021, 04:19 PM)josemendez Wrote: Hi, Code: ObiSolver.ParticleInActor pa = solver.particleToActor[particleIndex];
25-06-2021, 12:03 PM
(This post was last modified: 25-06-2021, 12:07 PM by josemendez.)
(24-06-2021, 04:39 PM)debruw Wrote: Hi there! I don't think I'll be able to post full functioning code today, I will on monday for sure. However at first glance the for loop looks suspicious indeed. RemoveAt(i) moves all elements in the list at indices larger than "i" one index back, and reduces the list length by one (see: https://docs.microsoft.com/en-us/dotnet/...ew=net-5.0) This will cause the for loop to skip over elements. When removing elements while iterating trough an array/list, do it backwards: Code: for (int i = obiRopes[0].elements.Count -1; i >= pa.indexInActor + 1, --i) This will prevent any issues, since all elements shifted when removing one have been already visited by the for loop. It's also more efficient, since the amount of shifting that needs to be done is minimized. There might be other issues with your code, hold on and I'll post a fully working version asap.
25-06-2021, 08:30 PM
28-06-2021, 09:35 AM
(This post was last modified: 28-06-2021, 09:35 AM by josemendez.)
Here's working code to remove part of the rope after a cut. I've subscribed to the rope's OnRopeTorn event, there I remove all elements after the cut.
The only caveat is when iterating trough elements and removing them, you must iterate backwards to avoid skipping over elements. Code: using UnityEngine;
28-06-2021, 05:36 PM
(28-06-2021, 09:35 AM)josemendez Wrote: Here's working code to remove part of the rope after a cut. I've subscribed to the rope's OnRopeTorn event, there I remove all elements after the cut.Thank you so much i will be try this as soon as possible |
« Next Oldest | Next Newest »
|