worms like rope mechanic

Here's the place to get help and discuss features. The focus is on the C++ version, but generic questions are welcome.
Posts: 1
Joined: Sat Sep 23, 2017 4:06 am

worms like rope mechanic

Postby mani » Sat Sep 23, 2017 4:42 am

Hello Friends,

i am using box2d to implement a "worms like" rope mechanic and have a question.
A rough explanation of my problem can be seen in the following animation.

rope_problem.gif (116.7 KiB) Viewed 379 times

The left animation runs at a high frame rate and my current algorithm works in this specific case, but on the right you can see that at a lower frame rate it fails.

I have the player connected to the level by a distant joint and am firing raycasts from the players position to the connection point each frame to find intersections. If the raycast hits something, i am creating a new joint at that point and save the previous connection point along with the angle of the rope. If i pass the angle again in the other direction i remove the last joint and reconnect to the previous point. The level is a static body with a list of shape fixtures.

This works only if i add a threshold to the angle when i pass it in the other direction, otherwise it would instantly find a new intersection point with the next raycast.

I need to find the right point where the new joint should be connected.

problem.png (14.59 KiB) Viewed 379 times

My question now is what would be the most efficient method to find the right point and can box2d help me with that?

My first approach would be to find all points within the triangle ABC and then find the nearest point to the line BC. but i really don’t know how to find those points efficiently.

Can someone push me in the right direction?

Thank you very much.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest