I think the better thing to change to have a good behaviour is the rest length of the spring. If a muscle contract, its length get smaller. It’s also easier to control the length than tweaking the stiffnes which also allow to change the length but with less control.
I created a small playground where I attached a spring between 2 boxes. The spring part start at line 70. I read a post where someone was using setLinearLimits to change the rest length (c++ - What are "frame A" and "frame B" in btGeneric6DofConstraint's constructor for? - Game Development Stack Exchange) . I tried to do the same but I get some strange behaviour. Changing linear limits to get a minimal restlength imply that it’s behave like a rod. I made a rotation to the box to display this. Just uncomment line 108-109.
A call to setEquilibriumPoint is needed to achieve what you want. This method has been exposed in ammo.js a couple days ago. I’m going to update BabylonJS and will let you know when you can try it again.
In this PG13, I added the equilibrium point on the y axis to -10 (line 131). The distance between the 2 boxes is now correct.
But it behave still like a rod and not a rubber band. The spring is going straight to the right.
It is done with CannonJS wich I cannot use because it doesn’t handle the compound bodies at the time I’m writing this reply ;s.
But I hope this is can be done in Ammojs.
I’m not sure for the 2 springs. I think it will add another behaviour and it the problem will be the same no ?
If Ammojs is not suited for this, I think I’m gonna try to create a compound body with cannonjs.
.
It seems to behave well. I think I’ll have to tweak some of the limits of the cone.
One question remain, is’nt this fix too heavy for like 200 springs with each 2 joints. There will be like 400 cone contraints and 200 spring constraints.
I don’t know how fast it will be on your target. Is there a way you can enable/disable joints based on some distance (camera, player,…). The idea is to only activate the joints you subject to interact with.