Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Spawning a rope along a line the player draws
#1
Pregunta 
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:

  1. Let the player drag the cursor around a 2D plane, spawning a rope as they go (as if drawing a line with a pen)
  2. The rope should spawn in a way that it matches the drawn path as closely as the simulation settings allow.
  3. The rope should be a live simulation while it is being drawn (I don't want to draw a spline and then convert it into a rope once the cursor is released).
   

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()
{
    // _dragAndDrop is an object that follows the cursor if isDragging is TRUE
    if(_dragAndDrop.isDragging)
    {
        // Calculate the distance between _tipTransform and _dragAndDrop.transform
        float distance = Vector3.Distance(_tipRigidbody.transform.position, _dragAndDrop.transform.position);

        // Add that amount of distance to the end of the rope
        _cursor.cursorMu = 1.0f;
        _cursor.sourceMu = 0.0f;
        _cursor.ChangeLength(_rope.restLength + distance);

        // Tip rigidbody is attached to the end or the rope.               
        _tipRigidbody.transform.position = _dragAndDrop.transform.position;
    }
}

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?
Reply


Messages In This Thread
Spawning a rope along a line the player draws - by joegatling - 20-03-2024, 12:25 AM