| 1 | <div style="text-align:left;color:#000000; background-color:#ffffff; border:solid black 1px; padding:0.5em 1em 0.5em 1em; overflow:auto;font-size:small; font-family:monospace; "><em><span style="color:#236e25;">// Faked top down friction.<br /> |
| 2 | </span></em><br /> |
| 3 | <em><span style="color:#236e25;">// A pivot joint configured this way will calculate friction against the ground for games with a top down perspective.<br /> |
| 4 | // Because the joint correction is disabled, the joint will not recenter itself and only apply to the velocity.<br /> |
| 5 | // The force the joint applies when changing the velocity will be clamped by the max force<br /> |
| 6 | // and this causes it to work exactly like friction!<br /> |
| 7 | </span></em>cpConstraint *pivot = <span style="color:#003668;">cpSpaceAddConstraint</span>(space, <span style="color:#003668;">cpPivotJointNew2</span>(staticBody, body, cpvzero, cpvzero));<br /> |
| 8 | <span style="color:#003668;">cpConstraintSetMaxBias</span>(pivot, <span style="color:#0000ff;">0.0f</span>); <em><span style="color:#236e25;">// disable joint correction<br /> |
| 9 | </span></em><span style="color:#003668;">cpConstraintSetMaxForce</span>(pivot, <span style="color:#0000ff;">1000.0f</span>);<br /> |
| 10 | <br /> |
| 11 | <em><span style="color:#236e25;">// The pivot joint doesn't apply rotational forces, use a gear joint with a ratio of 1.0 for that.<br /> |
| 12 | </span></em>cpConstraint *gear = <span style="color:#003668;">cpSpaceAddConstraint</span>(space, <span style="color:#003668;">cpGearJointNew</span>(staticBody, body, <span style="color:#0000ff;">0.0f</span>, <span style="color:#0000ff;">1.0f</span>));<br /> |
| 13 | <span style="color:#003668;">cpConstraintSetMaxBias</span>(gear, <span style="color:#0000ff;">0.0f</span>); <em><span style="color:#236e25;">// disable joint correction<br /> |
| 14 | </span></em><span style="color:#003668;">cpConstraintSetMaxForce</span>(gear, <span style="color:#0000ff;">5000.0f</span>);<br /> |
| 15 | <br /> |
| 16 | <em><span style="color:#236e25;">// Also, instead of connecting the joints to a static body, you can connect them to an infinite mass rogue body.<br /> |
| 17 | // You can then use the rogue body as a control body to the connected body. See the Tank demo as an example.</span></em></div> |