Breakable springs
2 posts • Page 1 of 1
Breakable springs
Cool! Now we have breakable springs!
I didn't manage to make nice visual effect of splitting spring into parts due to some bugs but it will be done soon.
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.
I didn't manage to make nice visual effect of splitting spring into parts due to some bugs but it will be done soon.
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...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: Breakable springs
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.
_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...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
2 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 5 guests




