- Home /
Need Help Making A 2d Grappling hook
What I need is to make a grappling hook that only pulls the player up and also once the players reached the top of the hook to have it automatically detach. Don't Fell like you have to post a script for this (although it would be very helpful) I've looked around on youtube but all the tutorials are outdated and not specific enough so I came here. If you could send me in the right direction or have some tips to accomplish this task it will be greatly appreciated. Really any tips will be helpful im fairly new to unity.
Can you talk more about your grappling hook functionality? Is it like in Worms? As in does the grappling hook travel in a straight line or does it travel in a curved manner?
Answer by thesavvycow · Apr 05, 2018 at 06:38 PM
The function of the grappling hook is to just pull the player in the direction where they tap. So if the grapple in worms only pulls in one direction then that exactly what I need.
Answer by Nathidraws · Apr 30, 2020 at 10:53 AM
Same.. Im getting stressed out because of the things not working properly...
Answer by Tario · Apr 29, 2020 at 03:05 PM
I would do this with a list and raycasts.
For this recipe you will need:
an understanding of List<> data structures
an understanding of raycasts,
an understanding of the equations that define the geometry of a circle
a character controller that can move towards any given point in space
The player shoots the hook, you shoot a raycast. If the raycast hits something, your grapple is established. Add your hit point to a List< Vector3 >.
Each frame that the list has at least one thing in it, take the last item in the list and cast a ray to that point from the player. If your ray intersects something, add that new intersection to the end of the list.
Mentally define a circle where the radius is the distance from the last position in your list to the player and the center is the last position in the list. Using the equations for the circumference of a circle, limit the player's movements to either travel along the circumference or reduce the radius of the circle.
If your list has more than 1 entry in it, use Vector3.Angle() to compare the angle between the player's position and each of the last two entries in the list. If the angle between the player and the last point is the same as the angle between the player and the second to last point, remove the last point from the list.
If the radius of your circle ends up lower than a certain threshold, remove the last point from the list.
If your list is ever empty, you have reached the point the grappleing hook was attached to.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to call OnTriggerEnter once 5 Answers
2D box colliders not touching but are colliding, how to fix? 0 Answers
Weapon System with collide detection (Helps with script pls)!!! 0 Answers