Thursday, November 8, 2012

Game-off: Day 5

Day 5 is done, and this blog post is late! (Typical, really.)

Today was all about integrating my rope implementation into the game.

(Clicky for make big)

The ropes are pretty much the same, except I can now attach them at arbitrary points on the bodies (not just the center point). I also changed the damped spring (between the two control points) to a normal slide joint. The damped spring was too difficult (impossible?) to tune such that its max length would be 1/3 of the total rope length. That's because the actual length will depend entirely on the forces moving the control point apart, and the strength of the spring. A slide joint works well enough anyway.

The most difficult part was getting the rope to draw properly with the offset anchor points. And that's because when the bodies rotate, you need to rotate the anchor points as well. I knew Chipmunk provided a function to rotate vectors, but I didn't know how to use it until I spotted this forum post. The body.rot property is just a vector composed of the cos() and sin() of the body's rotation angle. So simply rotating the anchor vector by the body.rot vector makes it all magically come together. It's a thing of beauty! :D Thanks Chipmunk! I love you.

No comments: