- Home /
Grappling Hook/Arm in 2D
Hi This is my first time making a 2D platformer in Unity, and I'm not very good at coding. So that's why I'm here asking for help. The grappling system I'm developing has many differents parts, and I have broken them down in a requirements list:
Instant pull the player (Fast like a dashing ability)
Player can only use it once, and it replenish when they touch the ground.
The arm can only shoot in two direction. Forward or Forward at a 30 degree angle. (So the player doesn't use the mouse) I made this Diagram to better explain what I mean by the player only has two option.
If the arm doesn't hit anything, it will retract back to player. And then they have to touch ground, if they want to activate it again.
If the player hit the edge of a obstacle, they will sling up over the obstacle and land top of it. ^^Like this ^^ So it is basically the same Grappling Hook from "Dying Light", but in 2D.
The player is made using a RigidBody2D, so my goal is to add force to my player in the direction of the grapplingPoint.
So far I'm just trying to create a raycast that shoots forward and then move the player to that point.
if (Input.GetButtonDown("Fire1") && !wallGrab && !wallSlide)
{
isGrappling = true;
GrapplingArm();
}
private void GrapplingArm()
{
RaycastHit2D hitInfo = Physics2D.Raycast(grapplePoint.position, grapplePoint.right);
if (hitInfo)
{
Debug.Log(hitInfo.distance);
}
Vector2 grappleDirection = (grapplePoint.position - transform.position);
rb.velocity = grappleDirection.normalized * grappleSpeed; //Move player to grapplepoint
}
But that doesn't work. So my questions are: How do I make this work? Or maybe should i try another method, like using the Distance Joint 2D? and if yes, will this method fulfill the requirements?
And now I just want to thank you for reading all this. And every comment will be much appreciated.
Small update: I tweaked the grappleSpeed and have now noticed that when i press the Fire1 button the player teleports to a point... And when the player jump and press the button, the player will be pulled down to the ground faster. Here's a video, showing what is happening.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
2D Physics Problem? 1 Answer
Default Contact Offset Problems 1 Answer
While Moving Left or Right my character falls more slowly. 2 Answers