- Home /
unity 2d how to make grappling hook
i want to make a grappling hook with it's metal end how can i do that ? i want it to move and have limit distance and speed
Answer by Rocketman_Dan · Sep 26, 2019 at 02:09 AM
Get a vector from the mouse position to the player. Translate the head of the hook towards the mouse position. If the magnitude of the vector between the hook and the player goes over a set limit (your distance) then stop it and translate back to the player (or don't allow it to fire in the first place if the distance from mouse to player is too big).
To get it to detect hits and stick put colliders on the hook as well as the collidable environment. If OnCollisionEnter
fires you check the parameters of the object it hit.
If it's collided with something you are allowed to grapple onto then you make the hook stay in place and translate the player towards the hook.
this is a top level view of how I would approach a grappling hook. You may not know how to do all of these things but they should be much more approachable to find now.
Checklist of things you need:
ScreenToWorldPoint of mouse position
getting the magnitude of a vector
translating towards a point over time
collision detection using Unity physics colliders (remember to use the 2D ones)
Your answer
Follow this Question
Related Questions
Having issue with enemy ai shooting 0 Answers
Platformer movement using Unity physics 1 Answer
Grappling Hook in 2.5d Game 0 Answers
How to get GUI text to appear on screen in 2d? 1 Answer
How do I get my character to dash up? 0 Answers