I am making my first game in Unity 2D and I want straight line drawn by user on the screen to get wrap around the perimeter of the 2D gameobject. For example, a straight line will get drawn until user holds his finger on the screen. As soon as user stops touching the screen, the line will get wrap around the perimeter of the gameobject.

This is a video that shows exactly what I want.

So, any idea how do I go about this?

New contributor
Rick K. is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 2
    \$\begingroup\$ Can you diagram-out the steps of this drawing and wrapping process, so we can be sure we understand exactly the behaviour you have in mind? \$\endgroup\$ – DMGregory Jan 10 at 12:32
  • \$\begingroup\$ @DMGregory Here's the video that shows exactly what I want: youtube.com/watch?v=rbhGLSM35K8 \$\endgroup\$ – Rick K. Jan 10 at 13:41
  • 1
    \$\begingroup\$ I think it's understandable that some game developers may have ethical qualms about providing a complete solution to clone an existing game's signature mechanic. So you might find you get better answers if you can narrow this down a bit. How are you thinking about the steps of the problem so far? What parts do you know how to implement / what parts have you successfully implemented already? If you can narrow down a specific part of this interaction you need help with, you're more likely to get detailed answers. \$\endgroup\$ – DMGregory Jan 10 at 13:55
  • \$\begingroup\$ @DMGregory I implemented the line drawing part. Now, what I don't know is to make that line wrap around the gameobject. I followed this tutorial to learn how to detect and store the wrapping points. But I didn't quite understand the wrapping part properly. I am thinking I should put 4 invisible lines at the four sides to fire raycast and store the collider points for the wrapping part and then use those points for wrapping. But then again the problem is implementation part. I don't know how to I implement it. \$\endgroup\$ – Rick K. Jan 10 at 16:41
  • 1
    \$\begingroup\$ Great. Next: edit your question to walk us through the problem, and how you've tried applying the tutorial's method to solve it. Call out the exact spot in your implementation where you're stuck. \$\endgroup\$ – DMGregory Jan 10 at 17:06

Your Answer

Rick K. is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.