# Problems with creating soft body in processing

**URL:** https://discourse.processing.org/t/problems-with-creating-soft-body-in-processing/29535
**Category:** Coding Questions
**Created:** [April 21, 2021, 7:57am UTC](https://discourse.processing.org/t/problems-with-creating-soft-body-in-processing/29535 "2021-04-21T07:57:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Rafsing](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/rafsing/32/10134_2.png) [@Rafsing](https://discourse.processing.org/u/Rafsing)
#### Post date: [April 21, 2021, 7:57am UTC](https://discourse.processing.org/t/problems-with-creating-soft-body-in-processing/29535/1 "2021-04-21T07:57:20Z")

</div>

I am having trouble forming a soft body where each side is a spring. When they are created, they do not merge into one object, but create as many springs as there are vertices in the figure. This code is responsible for the formation of the body:

```auto
 SoftBody(ArrayList<PVector> verticies, float mass_)
  {

    for (int i = 0; i < verticies.size() - 1; i++)
    {
      sidesAndDiagonals.add(new Spring(new Circum(verticies.get(i).x, verticies.get(i).y, verticiesRadius, mass_/verticies.size()), new Circum(verticies.get(i + 1).x, verticies.get(i + 1).y, verticiesRadius, mass_/verticies.size()), springRestLenght));
    }

    sidesAndDiagonals.add(new Spring(new Circum(verticies.get(verticies.size() - 1).x, verticies.get(verticies.size() - 1).y, verticiesRadius, mass_/verticies.size()), 
      new Circum(verticies.get(0).x, verticies.get(0).y, verticiesRadius, mass_/verticies.size()), springRestLenght));

    mass = mass_;
  }

```

This is my entire code: [https://pastebin.com/1XJrWCne](https://pastebin.com/1XJrWCne)

---

<div class="post-metadata">

### Author: ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)
#### Post date: [April 21, 2021, 10:09am UTC](https://discourse.processing.org/t/problems-with-creating-soft-body-in-processing/29535/2 "2021-04-21T10:09:05Z")

</div>

Hi! It’s nicely divided into classes while I cannot spot the issue at a glance. One potential problem is that you are updating and drawing at the same time. This can lead to a problem because the bodies and springs interact with each other, so usually it’s better to split the update and draw functions, and once all the bodies are updated, do another iteration to draw.

You could add debug draw mode to show the vectors of force, for example. This may help spot the problem quickly instead of examining the code line by line.
