![]() |
Beginner looking for a way to cut rope on swipe - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html) +--- Thread: Beginner looking for a way to cut rope on swipe (/thread-2547.html) |
Beginner looking for a way to cut rope on swipe - CuriousJacob - 18-10-2020 I apologize if this kind of question has been asked before, or if it is too vague. I wish to implement a cutting mechanic in my game where by if the user swipes across a rope, it will cut the rope at the point of touch. I am unsure on how to proceed with this as I am fairly new to coding. If someone could please take the time to explain how to do this, or if there's any existing code for a similar situation I could peruse, it would be highly appreciated. Thank you so much. RE: Beginner looking for a way to cut rope on swipe - josemendez - 19-10-2020 (18-10-2020, 02:28 PM)CuriousJacob Wrote: I apologize if this kind of question has been asked before, or if it is too vague. I wish to implement a cutting mechanic in my game where by if the user swipes across a rope, it will cut the rope at the point of touch. I am unsure on how to proceed with this as I am fairly new to coding. If someone could please take the time to explain how to do this, or if there's any existing code for a similar situation I could peruse, it would be highly appreciated. Thank you so much. Hi Jacob, The steps to do this would look roughly like this: 1.- Find the rope element(s) intersected by the swipe. 2.- Call Tear() for each one of these elements. The most complicated part of this is #1, as there's no ready-made solution and it involves a bit too much math for a beginner. Assuming this is 2D, the basic building block for this is determining whether 2 line segments intersect. You can find quite some info online and implementations in different languages, for instance: https://www.geeksforgeeks.org/check-if-two-given-line-segments-intersect/ Once you have a working segment intersection function, you can do: Code: // 1: find out rope elements intersecting the swipe, and put them in a list. |