- Home /
Grapple Gun Parkour
So before I begin I just want to say thank you for trying to understand and help with with this problem, I know it's very particular.
So far I have a system that utilizes a spring joint and a line renderer that allows your to swing on any position of choice. I also have a system that will propel that player towards the grapple point (b spring joint), utilizing this function:
void reel()
{
if (IsGrappling())
{
if (Vector3.Distance(player.position, grapplePoint) > minReelDis)
{
Vector3 normalized = (grapplePoint - player.position).normalized;
rb.velocity = Vector3.MoveTowards(rb.velocity, normalized * reelSpeed, 1.0f);
}
else
{
rb.velocity = Vector3.zero;
}
}
}
The problem is that when you have any momentum that offsets the player while moving towards the grapple point, such as swaying in the air, it will overshoot the grapple point. I only want this to happen based on which of the WASD the player is pressing, kind of like swinging your body in the direction you want to move, otherwise, I want the player to move directly towards the grapple point.
Here is an example of what i want my movement to look like from a fan game on AoT I found:
if can post or upload any of my scripts if needed. One more thing, I'm using two grapple guns with one either side of the player that you can control independently.
Looks like your links are broken, can you try to repost so I have a better idea what you are looking for?
As far as fixing your problem, it looks like you are on the right track to me. The next thing I would try in this situation is try to scale your velocity correction by how close you are to your grapple point. In other words, when you are far from the grapple point it should work as it does now, but as you reel in it starts steering your velocity more rigidly.
Something like
//Play with these values
public float $$anonymous$$GrappleDistance;
public float maxGrappleDistance;
public float $$anonymous$$GrappleRigidity;
public float maxGrappleRigidity;
void reel()
{
if (IsGrappling())
{
float distanceToGP = Vector3.Distance(player.position, grapplePoint);
if (distanceToGP > $$anonymous$$ReelDis)
{
//if you are at maxGrappleDistance or beyond, you will have $$anonymous$$GrappleRigidity
//as you approach $$anonymous$$GrappleDistance you will become more rigid, up to maxGrappleRigidity
float normalizedDistance = (distanceToGP - $$anonymous$$GrappleDistance) / (maxGrappleDistance - $$anonymous$$GrappleDistance);
normalizedDistance = 1f - Mathf.Clamp(normalizedDistance, 0f ,1f);
float grappleRigidity = $$anonymous$$GrappleRigidity + (normalizedDistance * (maxGrappleRigidity - $$anonymous$$GrappleRigidity));
Vector3 normalized = (grapplePoint - player.position).normalized;
rb.velocity = Vector3.MoveTowards(rb.velocity, normalized * reelSpeed, grappleRigidity);
}
else
{
rb.velocity = Vector3.zero;
}
}
}
@unity_ek98vnTRplGj8Q Actually, here's a video from the game I referenced: Video of movement. Otherwise this helped a lot, now the player will no longer overshoot, but I still cant control the direction of my movement. Is there any way I can influence the direction of my movement while grappling, such as changing the $$anonymous$$Distance based on what direction your moving, ect. Also, not entirely important, but is there any way to make accelerate instead of having constant velocity?
You can always just add any movement vector to your velocity vector to give some character control during grappling. Being able to replicate the video exactly will take a lot of experimenting, but likely what you will need to do is calculate your velocity value from your grapple first. If you want to accelerate then you can ramp this velocity value up over time after you first grapple on to something. Then, you can calculate an additional velocity value based on any movement keys that are being pressed and add them together.