# How to achieve simple cloth-like physics simulation

**URL:** <https://forum.babylonjs.com/t/how-to-achieve-simple-cloth-like-physics-simulation/8287>\
**Category:** Questions\
**Created:** [January 28, 2020, 10:15pm UTC](https://forum.babylonjs.com/t/how-to-achieve-simple-cloth-like-physics-simulation/8287 "2020-01-28T22:15:34Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pashtet](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pashtet/32/4364_2.png) [@Pashtet](https://forum.babylonjs.com/u/Pashtet)\
**Post date:** [January 28, 2020, 10:15pm UTC](https://forum.babylonjs.com/t/how-to-achieve-simple-cloth-like-physics-simulation/8287/1 "2020-01-28T22:15:34Z")

</div>

Hello!  
Has anyone made effect like that (attention on car’s antenna)?  
I have absolutely no idea how to do this.  
May be someone has an experience in that kind of features?

I don’t even know how this behaviors named so i can’t even google it ☹

[https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/3/3aa9289a18e638e8e3d5d1a30c97baf8fa969516.mp4](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/3/3aa9289a18e638e8e3d5d1a30c97baf8fa969516.mp4)

---

<div class="post-metadata">

**Author:** ![syntheticmagus](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/syntheticmagus/32/395_2.png) [@syntheticmagus](https://forum.babylonjs.com/u/syntheticmagus)\
**Post date:** [January 29, 2020, 12:04am UTC](https://forum.babylonjs.com/t/how-to-achieve-simple-cloth-like-physics-simulation/8287/2 "2020-01-29T00:04:22Z")

</div>

Hi Pashtet,

Sounds like you might be looking for how to [use a physics engine](https://doc.babylonjs.com/how_to/using_the_physics_engine#physics-joints), and specifically how to use spring joints (they’re mentioned on that doc page). There’s also a Playground demonstrating the use of Cannon’s built-in spring physics joint.

[https://www.babylonjs-playground.com/#1BHF6C](https://www.babylonjs-playground.com/#1BHF6C)

You might have to play around with it a bit if you’re going for a particular look/feel to the physics, but I think that’s a good place to start. If you end up wanting more precise control, it’s also not too difficult to write a custom “toy” spring mechanism to achieve a certain look ([here’s a quick one](https://playground.babylonjs.com/#SSN5EE) that doesn’t bother much with physical accuracy, but looks kind of fun). Hope this helps!

---

<div class="post-metadata">

**Author:** ![Pashtet](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pashtet/32/4364_2.png) [@Pashtet](https://forum.babylonjs.com/u/Pashtet)\
**Post date:** [January 29, 2020, 7:03am UTC](https://forum.babylonjs.com/t/how-to-achieve-simple-cloth-like-physics-simulation/8287/3 "2020-01-29T07:03:35Z")

</div>

Thank you so much! I’ll try it:)

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [January 29, 2020, 10:30am UTC](https://forum.babylonjs.com/t/how-to-achieve-simple-cloth-like-physics-simulation/8287/4 "2020-01-29T10:30:09Z")

</div>

Old, but might help -

[https://blog.raananweber.com/2016/04/03/cloth-physics-simulation-for-babylon-js/](https://blog.raananweber.com/2016/04/03/cloth-physics-simulation-for-babylon-js/)

(Shameless self-promotion! 🙂 )

---

<div class="post-metadata">

**Author:** ![Pashtet](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pashtet/32/4364_2.png) [@Pashtet](https://forum.babylonjs.com/u/Pashtet)\
**Post date:** [January 29, 2020, 10:52am UTC](https://forum.babylonjs.com/t/how-to-achieve-simple-cloth-like-physics-simulation/8287/5 "2020-01-29T10:52:35Z")

</div>

Thank you! I have already red your article, it awesome) But I a bit confused with that method, I can’t use this method when I’m using 3d model more complex than plane. At times, it seems to me that Skeloton and Bones are right way to solve my problem. But I haven’t found how to apply physics to Bone at the moment .

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [January 29, 2020, 11:03am UTC](https://forum.babylonjs.com/t/how-to-achieve-simple-cloth-like-physics-simulation/8287/6 "2020-01-29T11:03:37Z")

</div>

Physics on bones will work very similar to the way the cloth is working - you add particles to the bone’s position, connect them with any join you think fits (distance joint exists in all engines, spring joint is available in cannon) and update the bone’s position every frame based on what the physics engine delivers back. So:

1. Add a particle per bone position (I would disable the bidirectional transformation to have better performance - it is a flag in the impostor options)
2. Set each particles transformation according to the absolute position of the bone
3. Connect those particles using joints
4. On a before-render function, get the (updated) positions of the bone impostors and update the bone positions accordingly.

If you limit the joint’s allowed angles you can get the effect you wanted

On a different note, you can achieve this effect without a physics engine (at least not on the antenna). Create the mesh, and update its movement according to the change in acceleration in the (local) Z axis of the car. You know the car is moving in a specific speed - move the upper pat of the antenna a bit to the back if it goes forward. When the can breaks (acceleration delta is negative) start moving the antenna forward. I dont see why it can’t look realistic without a physics engine.

---

<div class="post-metadata">

**Author:** ![Pashtet](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pashtet/32/4364_2.png) [@Pashtet](https://forum.babylonjs.com/u/Pashtet)\
**Post date:** [January 30, 2020, 2:30pm UTC](https://forum.babylonjs.com/t/how-to-achieve-simple-cloth-like-physics-simulation/8287/8 "2020-01-30T14:30:17Z")

</div>

I have tried to implement this feature, but faced with problem with gravity (Distance and Spring joints doesn’t have “lock” features). I have tried to implement with LockJoint and I’ve got some results - [Babylon.js Playground](https://www.babylonjs-playground.com/#5GPE0Q)

I keep trying 🙂

---

<div class="post-metadata">

**Author:** ![Wingnut](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/wingnut/32/53_2.png) [@Wingnut](https://forum.babylonjs.com/u/Wingnut)\
**Post date:** [January 30, 2020, 2:58pm UTC](https://forum.babylonjs.com/t/how-to-achieve-simple-cloth-like-physics-simulation/8287/9 "2020-01-30T14:58:26Z")

</div>

Hi guys. [https://www.babylonjs-playground.com/#480ZBN#108](https://www.babylonjs-playground.com/#480ZBN#108)

Seeing we have AmmoJS nearby, we also have ropeImpostors nearby.

Just begun. Started with someone elses PG. That whole PG series is packed-with Ammo soft-body demos, I believe.

Forced-positioning in line 35… never a good idea for a mesh with a physicsImpostor, so might be troubles there. Plus, I dunno if a rope impostor is SUPPOSED TO work… “standing”. I don’t know how to set its restitution, mass, inertia, etc, either. New stuff for Mr. Wingnut.

Are we seeing SOME “bend” as this thing cycles laterally? Not sure. It seems opposite bend-direction from what it _should_ be. Could be eye-foolery. 🙂

[https://playground.babylonjs.com/#1KPF49#42](https://playground.babylonjs.com/#1KPF49#42) - Classic chain of hinge joints in Cannon… MIGHT be able to be made “stiff” by moving connectedPivots on joints… up or down. Not sure. Might be difficult to replace spheres with tube-sections. All sorts of obstacles to “smooth linear bend” there, too. Essentially, this is one “column” of cloth… using larger sphereImpostors instead of particleImpostors or Ammo’s method.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [January 30, 2020, 3:10pm UTC](https://forum.babylonjs.com/t/how-to-achieve-simple-cloth-like-physics-simulation/8287/10 "2020-01-30T15:10:28Z")

</div>

How about using a point-to-point joint?

[https://www.babylonjs-playground.com/#5GPE0Q#1](https://www.babylonjs-playground.com/#5GPE0Q#1)

---

<div class="post-metadata">

**Author:** ![Pashtet](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pashtet/32/4364_2.png) [@Pashtet](https://forum.babylonjs.com/u/Pashtet)\
**Post date:** [January 30, 2020, 4:05pm UTC](https://forum.babylonjs.com/t/how-to-achieve-simple-cloth-like-physics-simulation/8287/11 "2020-01-30T16:05:16Z")

</div>

Thank you, Master 🙂

I changed bones position synchronisation to rotation, now it looks almost as I wish. [https://www.babylonjs-playground.com/#5GPE0Q#4](https://www.babylonjs-playground.com/#5GPE0Q#4)

Now I’ll try to make it more solid (elastic)

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [January 30, 2020, 4:10pm UTC](https://forum.babylonjs.com/t/how-to-achieve-simple-cloth-like-physics-simulation/8287/12 "2020-01-30T16:10:27Z")

</div>

Awesome!!!

With your permission, I am going to make it a WebXR boxing scene 🙂 . Seems like a perfect way to test physics on the controllers

---

<div class="post-metadata">

**Author:** ![Pashtet](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pashtet/32/4364_2.png) [@Pashtet](https://forum.babylonjs.com/u/Pashtet)\
**Post date:** [January 30, 2020, 4:13pm UTC](https://forum.babylonjs.com/t/how-to-achieve-simple-cloth-like-physics-simulation/8287/13 "2020-01-30T16:13:26Z")

</div>

Of course! I will only be happy 🙂

---

<div class="post-metadata">

**Author:** ![Pashtet](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pashtet/32/4364_2.png) [@Pashtet](https://forum.babylonjs.com/u/Pashtet)\
**Post date:** [January 30, 2020, 4:18pm UTC](https://forum.babylonjs.com/t/how-to-achieve-simple-cloth-like-physics-simulation/8287/14 "2020-01-30T16:18:34Z")

</div>

Meh Ammo… It can do everything, but it so difficult for me. I think Cannon.js is my limit:)
