Breakable springs

About advanced scenes, and the Thyme scripting language used in Algodoo.

Breakable springs

Postby Kilinich » Tue Jan 17, 2012 1:35 pm

Cool! Now we have breakable springs! :thumbup:
I didn't manage to make nice visual effect of splitting spring into parts due to some bugs but it will be done soon.

Rating: rated 6
Filesize: 53.38 kB
Comments: 1
Ratings: 3
download


So... select spring without endpoints (with ALT-key, make sure you've select only spring).
Put that code in script menu of selected spring.
Adjust _distanceLimit and _forceLimit to desired values.

Code: Select all
_distanceLimit := +inf;
_forceLimit := +inf;
_distance := {
  pos0 := [0,0]; pos1 := [0,0];
  spring := readable(owner);
  end0 := readable(scene.entityByID(spring.lineEndPoint0));
  end0.geom == 0 ? {pos0 = end0.relPoint} : {
    geom := readable(scene.entityByGeomId(end0.geom));
    a := geom.angle;
    r := end0.relPoint;
    pos0 = geom.pos + [(math.cos(a) * r(0) - math.sin(a) * r(1)), (math.cos(a) * r(1)) + math.sin(a) * r(0)];
  };
  end1 := readable(scene.entityByID(spring.lineEndPoint1));
  end1.geom == 0 ? {pos1 = end1.relPoint} : {
    geom := readable(scene.entityByGeomId(end1.geom));
    a := geom.angle;
    r := end1.relPoint;
    pos1 = geom.pos + [(math.cos(a) * r(0) - math.sin(a) * r(1)), (math.cos(a) * r(1)) + math.sin(a) * r(0)];
  };
  d := pos0 - pos1;
  (d(0)*d(0) + d(1)*d(1))^0.5
};
_stretch := {owner._distance - owner.length};
_force := {owner._stretch * owner.constant};
_onSpringBreak := {scene.removeEntity(owner)};
_color := color;
color = {(owner -> {_force * _force > _forceLimit * _forceLimit || _stretch * _stretch > _distanceLimit * _distanceLimit}) ? {owner._onSpringBreak} : _color};
Last edited by Kilinich on Tue Jan 17, 2012 1:52 pm, edited 1 time in total.
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Breakable springs

Postby Kilinich » Tue Jan 17, 2012 1:51 pm

Actually you've got a little bit more:

_distance is real length of spring
_stretсh is delta from initial length
_force is force generated by spring
and finally in onSpringBreak you could not only kill it but stretch too.
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 5 guests