   mass spring grid problem...
  Hi everyone...I'm writing a shoot em up based loosely on geometry wars. one of the coolest things about it is a grid that's actually a mass spring system that is repelled when the player's ship moves (nodes are pushed away from the ship) and than get back to their original position when the ship is no longer there.I have implemented a mass spring system (a 2D one), and I'm using euler integration (it seems alright for this type of game, grid stays stable).Now the problem is that sometimes after nodes are pushed away by the ship (the ship applies a force away from it on all nodes in a certain distance), they stay stuck in place and don't get back to their original position. In debug mode i was able to see that the sum of forces on those nodes is almost zero, which means the forces applied on it are canceling each other out.The thing is, I cant for the life of me understand why... :)I'm not that great at physics, and i was wondering if someone here could take a look? I read somewhere that cloth simulation can "fold on itself" - maybe that's the case here? Oh, an important piece of info - each node in connected to the 8 nodes surrounding it (4 horizontal+vertical, 4 diagonal). I've read somewhere that it's better to also connect each node the the second level of neghibours (2 nodes away from the current node) to allow better simulation.k is set to 0.005.Any help/suggestions would be appreciated. I've attached a screenshot of the problem. notice the strange grid state on the top left (kind of hard to see)- it simply stays in this position 
  I don't know the answer to your question, but that looks cool - let us know when there's a version we can download :-)   ;  Are your 'edge' nodes tied to a fixed frame by springs too? If you don't tie the grid down to something then the edges will become distorted over time.   ;  this problem is more generally known as 'inverting' of a computational mesh. if a node that is 'supposed' to be on the right of another suddenly is pushed to the left of it, it might stay there because the spring also changes direction, pushes to keep it there, ie it is inverted.i think the best solution here would be to modify the springs, so that they simpy cannot change direction: dont base their force on where the nodes are, but on where the nodes are supposed to be.say you have a node in position x1 and x2. you want a force function that is zero in rest and otherwise monotomically increasing. simple: force = constant * ((x2-x1)-restlength).this might seem less accurate than a hookean spring, but it will hardly matter, and will solve the inverting problem.   ;  I wouldn't use mass spring system for such special effect. I'd just use simple wave-ish equation for horizontal and vertical deviation of vertex from center point.like vel.x=vel.x*(1.0-damping_value*dt)+k*dt*(average of neighbouring x positions - p.x);vel.y=vel.y*(1.0-damping_value*dt)+k*dt*(average of neighbouring y positions - p.y);and make border points be fixed.It is also faster to simulate than mass-spring system.   ;Quote:Original post by DmytryI wouldn't use mass spring system for such special effect. I'd just use simple wave-ish equation for horizontal and vertical deviation of vertex from center point.like vel.x=vel.x*(1.0-damping_value*dt)+k*dt*(average of neighbouring x positions - p.x);vel.y=vel.y*(1.0-damping_value*dt)+k*dt*(average of neighbouring y positions - p.y);and make border points be fixed.It is also faster to simulate than mass-spring system.given that you can derive the wave equation from taking the limit of a linearized mass spring system, whats the difference between discretizing the wave equation or linearizing a mass-spring system?although starting from the wave equation does seem to be conceptually simpler, it should reduce to the same computations if both are optimized.   ;Quote:Original post by EelcoQuote:Original post by DmytryI wouldn't use mass spring system for such special effect. I'd just use simple wave-ish equation for horizontal and vertical deviation of vertex from center point.like vel.x=vel.x*(1.0-damping_value*dt)+k*dt*(average of neighbouring x positions - p.x);vel.y=vel.y*(1.0-damping_value*dt)+k*dt*(average of neighbouring y positions - p.y);and make border points be fixed.It is also faster to simulate than mass-spring system.given that you can derive the wave equation from taking the limit of a linearized mass spring system, whats the difference between discretizing the wave equation or linearizing a mass-spring system?although starting from the wave equation does seem to be conceptually simpler, it should reduce to the same computations if both are optimized.Indeed, the wave equation itself is same as limit of linearized mass spring system. (and indeed in real world there's no wave equation in mechanics but only mass spring systems).The point is that it will not have problems like what OP is getting. I.e. for the task(waves ala game grid wars) it is better than the system of point masses connected by springs, and better than system of point masses connected by springs with additional springs attached to places where points must be.   ;Quote:Original post by DmytryQuote:Original post by EelcoQuote:Original post by DmytryI wouldn't use mass spring system for such special effect. I'd just use simple wave-ish equation for horizontal and vertical deviation of vertex from center point.like vel.x=vel.x*(1.0-damping_value*dt)+k*dt*(average of neighbouring x positions - p.x);vel.y=vel.y*(1.0-damping_value*dt)+k*dt*(average of neighbouring y positions - p.y);and make border points be fixed.It is also faster to simulate than mass-spring system.given that you can derive the wave equation from taking the limit of a linearized mass spring system, whats the difference between discretizing the wave equation or linearizing a mass-spring system?although starting from the wave equation does seem to be conceptually simpler, it should reduce to the same computations if both are optimized.Indeed, the wave equation itself is same as limit of linearized mass spring system. (and indeed in real world there's no wave equation in mechanics but only mass spring systems).The point is that it will not have problems like what OP is getting. I.e. for the task(waves ala game grid wars) it is better than the system of point masses connected by springs, and better than system of point masses connected by springs with additional springs attached to places where points must be.i didnt actually want to suggest that, although i see how one might think so: my description wasnt exactly good. when i said: "dont base their force on where the nodes are, but on where the nodes are supposed to be.", i was thinking discarding 'where the nodes are' in terms of left/right of eachother relative to starting position, but instead take a linearized model, where the nodes stay in their 'supposed' ordering no matter what. but i see it is indeed highly ambigious, i should be more carefull what i write. :)in retrospect, all i should have said is: linearize around the equillibrum position, which boils down to the same thing you are suggesting.   ;  Ummm, thanks everyone for taking the time to answer...I must say I'm a bit confused by your answers though :)Do you all agree that switching to a different method than my current spring based one is a good idea?If so, can you please elaborate a bit on the mechanism or point me to a search word i can look for more info?I'm not that big an expert on physics as you see, so I'm learning as I progress...Again, thanks very much for your time!   ;  Basically, you can compute average position of four neighbouring points and use spring (with rest length =0) to attract each point there (don't worry, it is not a hack and waves will spread around). It will be essentially same math as what i and Eelco suggest.As for search, try looking for wave equation; essentially it is wave equations for x and y.   