Help Spawning a rope along a line the player draws - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html) +--- Thread: Help Spawning a rope along a line the player draws (/thread-4136.html) |
Spawning a rope along a line the player draws - joegatling - 20-03-2024 Hello, I am trying to create a game where the player can draw a rope in realtime by dragging the cursor around. My goal is:
Below is a code snippet from my first approach, but it doesn't seem to work. Here is a YouTube video of it in action. Code: void FixedUpdate() The code sort of works, but it seems to spawn too many particles. And then the rope just explodes. It would appear that changing the length in any way causes at least one new particle to be added. Is there a better way to achieve this? RE: Spawning a rope along a line the player draws - josemendez - 20-03-2024 Hi! Don't set the cursorMu before changing length. This will force the cursor to reset the amount of length already added to zero, which may cause particles to be added immediately one after another. Another problem is that you're not accounting for the rope's simulation, the newly added particle(s) should be placed in a straight line from the tip of the rope to the mouse cursor. Otherwise the rope is free to move anywhere and this might cause a feedback loop where the simulation itself increases the distance from the mouse if _tipRigidbody is attached to the rope. You're doing this in FixedUpdate, which means that some frames you might be increasing the length twice or more times, some frames you might not be increasing it at all. It may also update the length before or after ObiFixedUpdater(), so this might happen before or after simulation. A much better alternative would be to do this in LateUpdate(). let me know if I can be of further help! cheers, RE: Spawning a rope along a line the player draws - josemendez - 20-03-2024 Wrote a sample script for you. I'm using the solver's OnSubstep callback instead of LateUpdate, because I'm setting the first two particle positions every simulation step in order for the rope to roughly follow the direction of the cursor instead of increasing its length in whatever the current direction of the tip is. Also I'm raycasting against the XZ plane which might not be how your interaction system works, but the important parts should be easy to port to your system: Code: using UnityEngine; Video of results: |