For this project, i wanted to create a gameobject that can swing around by shooting grapping hooks into walls and ceilings. First i created a test-scene, containing sphere -shaped Player character, and some cube-walls to shoot the “hook” into.
Then i created a script that checks if the left mouse button is pressed. If so, it checks where you clicked and shoots raycast from gameobject to where-ever you clicked.
Console prints text “You clicked on [name of the object]”, for testing purposes.
If the object that we clicked has a rigidbody2D component attached to it, script will activate a Distance Joint between them.
And when we stop pressing the left mouse button, Distance Joint turns of.
Distance -value can be changed from the script. This way we can make our Grappling Hook’s “rope” longer and shorter. In this case, i made the “rope” to reel itself in with increasing speed.
It’s nothing special, but now we have a very basic shootable Grappling Hook, that we can use to swing around. I’m gonna get some coffee.
Since Unity Engine handles all touch inputs as mouse clicks,
Android build works without any extra work required.