So I got it to work... finally!
I had been using the 2D constraint code that's on Wikipedia, but it had for some reason been giving me a lot of excess energy in the system that would make things thrash and float around weirdly. I changed my code to something like the verlet chain constraint code that someone posted, and it works like a charm (99% of the time).
My new question is more of a brainstorming one... say I have a chain, and I want a projectile to break the chain and have the chain react (not just breaking, but also being pushed in the direction of the projectile). What are some ways to accomplish this?
My ideas are to (a) test for collisions between the chain links and the projectile. If there is a collision, set the colliding link's velocity (lastX and lastY values) to match the projectile's, update the chain (so that nearby chain links are also affected), and then break the chain off at that link. The problem with this method is that nothing will happen if the projectile slips between the chain links.
Alternatively, I could (b) test for collisions between the projectile and the line between the links. If there's a collision, change both nearby links' velocities, and then break the chain there.
I could also (c) test for collisions between the projectile and the line between the links, but if there's a collision, add two identical new links at the point of collision, set their velocities, and break them apart.
I'm pretty sure C would be most realistic, but also the most difficult to code and the most likely to cause errors. Right now I'm leaning towards B, but I'd like to know what you guys think. I've never really done this stuff before, so there's most likely a much better way to do it all, and I'd be interested to hear what others have done in the past.
Also, in rereading this post, I see that I've done a horrific job trying to explain things, and I apologize.
I had been using the 2D constraint code that's on Wikipedia, but it had for some reason been giving me a lot of excess energy in the system that would make things thrash and float around weirdly. I changed my code to something like the verlet chain constraint code that someone posted, and it works like a charm (99% of the time).
My new question is more of a brainstorming one... say I have a chain, and I want a projectile to break the chain and have the chain react (not just breaking, but also being pushed in the direction of the projectile). What are some ways to accomplish this?
My ideas are to (a) test for collisions between the chain links and the projectile. If there is a collision, set the colliding link's velocity (lastX and lastY values) to match the projectile's, update the chain (so that nearby chain links are also affected), and then break the chain off at that link. The problem with this method is that nothing will happen if the projectile slips between the chain links.
Alternatively, I could (b) test for collisions between the projectile and the line between the links. If there's a collision, change both nearby links' velocities, and then break the chain there.
I could also (c) test for collisions between the projectile and the line between the links, but if there's a collision, add two identical new links at the point of collision, set their velocities, and break them apart.
I'm pretty sure C would be most realistic, but also the most difficult to code and the most likely to cause errors. Right now I'm leaning towards B, but I'd like to know what you guys think. I've never really done this stuff before, so there's most likely a much better way to do it all, and I'd be interested to hear what others have done in the past.
Also, in rereading this post, I see that I've done a horrific job trying to explain things, and I apologize.