Great tutorial ! I modified it a litle was to a bit of randomness in the curve to make it feel more natural and it really looks very good. Thanks man !
@@bald3522 if you're talking about the grappling gun itself and not the animation, change the min distance and / or the spring values. You can also experiment with the damper. Sorry for the late response
i made the rope move in a circular motion by adding these lines, take a look if anyone interested Script "GrapplingRope": var right = Quaternion.LookRotation((grapplePoint - gunTipPosition).normalized) * Vector3.right; var offset = up * waveHeight * Mathf.Sin(delta * waveCount * Mathf.PI) * spring.Value * affectCurve.Evaluate(delta) + right * waveHeight * Mathf.Cos(delta * waveCount * Mathf.PI) * spring.Value * affectCurve.Evaluate(delta);
Full Script With Edit For Anyone Who didn't understand how to do it. using System.Collections; using System.Collections.Generic; using UnityEngine; public class Grappling_Rope_Gun : MonoBehaviour { private Spring spring; private LineRenderer lr; private Vector3 currentGrapplePosition; public Grappling_Gun grapplingGun; public int quality; public float damper; public float strength; public float velocity; public float waveCount; public float waveHeight; public AnimationCurve affectCurve; private float delta; void Awake() { lr = GetComponent(); spring = new Spring(); spring.SetTarget(0); } //Called after Update void LateUpdate() { DrawRope(); } void DrawRope() { //If not grappling, don't draw rope if (!grapplingGun.IsGrappling()) { currentGrapplePosition = grapplingGun.gunTip.position; spring.Reset(); if (lr.positionCount > 0) lr.positionCount = 0; return; } if (lr.positionCount == 0) { spring.SetVelocity(velocity); lr.positionCount = quality + 1; } spring.SetDamper(damper); spring.SetStrength(strength); spring.Update(Time.deltaTime); var grapplePoint = grapplingGun.GetGrapplePoint(); var gunTipPosition = grapplingGun.gunTip.position; var up = Quaternion.LookRotation((grapplePoint - gunTipPosition).normalized) * Vector3.up; currentGrapplePosition = Vector3.Lerp(currentGrapplePosition, grapplePoint, Time.deltaTime * 12f); for (var i = 0; i < quality + 1; i++) { var right = Quaternion.LookRotation((grapplePoint - gunTipPosition).normalized) * Vector3.right; var delta = i / (float)quality; var offset = up * waveHeight * Mathf.Sin(delta * waveCount * Mathf.PI) * spring.Value * affectCurve.Evaluate(delta) + right * waveHeight * Mathf.Cos(delta * waveCount * Mathf.PI) * spring.Value * affectCurve.Evaluate(delta); lr.SetPosition(i, Vector3.Lerp(gunTipPosition, currentGrapplePosition, delta) + offset); } } }
For anyone who cant get this to work. Dont skip any part of the video. I did so I missed the need to copy and past the spring script he created. its in the description if anyone else has the problem.
Yea, I kinda tried to explain, but I hoped I was as good at explaining as coding. I will try to improve that in future tutorials (if those even come) :D
it looks like karlson ngl. oh, you don't know what karlson is? KARLSON IS JUST A GAME DANI IS WORKING ON, WE'RE TRYING TO GET TO NUMBER ONE ON STEAM SO SMASH WISHLIST, GAMERs!
hello, this is a great tutorial i used this in several projects but i used it with danis script. and now i made my own graplle system and this is really hard to imploment.
Hi, great tutorial, it works very nice but I dont understand the formula you use in the Spring class. Can you tell what it's based on or some reference? I really want to know the math behind it.
@@Affax yessss you helped me so much with this i was searching for a video like this and the fact that you used dani's grap gun script made this so easy for me thank you :D
When i press play, it doesnt do it and i get this error: Invalid editor window UnityEditor.CurveEditorWindow UnityEditor.EditorApplicationLayout:FinalizePlaymodeLayout () what does this mean?
I am working on a game and I set it up to make it so that it is right click and left click but it wont let me put the right click gun in the script so I am unsure of what to do
hi, it is working amazingly and i only have two questions. 1. when i get too close to where i pinned the rope to it starts pushing me away 2. if i were to make it so if i pressed space it would draw me in, how would i go about doing that? Thanks!
Hi! To avoid being pushed away: joint.minDistance = 0f; To press spacebar and have it draw you in, put this in your void Update() under everything else: else if (Input.GetKeyDown(KeyCode.Space)) { joint.maxDistance = 0f; } else if (Input.GetKeyUp(KeyCode.Space)) { joint.maxDistance = 20f; //put whatever you want the "normal" distance to be here -- the distance when not reeled in } Hope this helps! If I can clear anything up for you, let me know!
@@-BRODEN is there a way to make the joint.maxDistance the current position you are in or the joint.maxDistance to be the position you grappled from? if there is, i would like to now but if there isnt, its totally fine
Hi im getting an error that says "LineRenderer.SetPosition index out of bounds" and it brings me to the line "lr.SetPosition(i, Vector3.Lerp(gunTipPosition, currentGrapplePosition, delta) + offset);" do you know what the issue could be?
It's probably because you missed one line or forgot to set the quality to something above 0: github.com/affaxltd/rope-tutorial/blob/f40f4cd095602e158b6ff43d594aa0b9622f864a/GrapplingRope.cs#L41
@@Affax Hey man I got a error saying Invalid editor window of type: UnityEditor.CurveEditorWindow, title: Curve UnityEditor.EditorApplication:Internal_CallDelayFunctions () and I copied everything from github, pls help.
Hello, nice video. Whenever i try to grapple onto something, it creates a straight line with your curvy one. Is there anyway to fix this or have I missed a part of this video?
Nice vid, but the thing is that ive made my own grappling script, and when I see this tutorial it is totally based on Dani's script, so it is hard to adapt to any other script
Well, it does make sense, I cannot really make a tutorial for each grappling hook implementation as the way people hand the rope is very different, though, in the future I might look into making a modular one where you just call start and end functions, we'll see. Hopefully the spring script and the changes to Dani's scripts help you integrate it into your own scripts though!
@@Affax Yeah I see. I managed to implement it now even if that was quite hard. I think the thing the made it complicated is that you didn't really explained how did you come to put some lines where they were. But I understand that you can't explain everything because it would make it too long haha. Anyways your video is still super usefull so yeah that's cool
@@slyzrl1361 i want to make a rope like sekiro like the way he trow the rope Do you got any helpful material or suggestion how can i make it ? for now i have used this code for throw and removed player movement tho only my rope is throw now.. If you Help Thx...
LineRenderer.SetPosition index out of bounds! UnityEngine.LineRenderer:SetPosition (int,UnityEngine.Vector3) GrapplingRope:DrawRope () (at Assets/Character/GrapplingRope.cs:59) GrapplingRope:LateUpdate () (at Assets/Character/GrapplingRope.cs:26)
I did everything according to the video but the rope has no animation and after the shot, the whole game starts lagging I don't know what to do with it. Can you help me, please?
damn i got tricked... i was half way done coding the spring script, but then i realised that u have a ready script at github... i deleted my spring script and copy pated the RAW Paste Data... I got tricked and now i lost all of the script i wrote...
i can't dude... it's 11:31pm and i have to finish my school project before tomorrow... and im not even half way there with programming my game.. Could someone PLEASE paste the "GrapplingRope" script?
It wasn't as good as I wanted. I also didn't know a whole lot about RUclips, so I just unlisted them. But I decided to redo the grappling video with more effort and skill put into it.
@@Affax Hi! I got it to work in 2D with a little bit of tweaking. One problem I'm having is that the end of the grappler is lerping, its not fixed at the grapple point, its smoothly following it.
@@JacksonAcademy1 Awesome to hear man! Yeah, 2D in Unity is close to 3D from what I hear, but due to lack of my skills in it I couldn't help. Thanks for watching the tutorial, hope it helped!
Great tutorial ! I modified it a litle was to a bit of randomness in the curve to make it feel more natural and it really looks very good. Thanks man !
do you know what value i should change to make it pull me in more/quicker?
@@bald3522 if you're talking about the grappling gun itself and not the animation, change the min distance and / or the spring values. You can also experiment with the damper. Sorry for the late response
This person is so good at teaching game development! He should become a game developer or something..
yoooo, its nice to see finnish game devs :D
i do games too and i'm from finalnd
only 624 subs? lemme give you one more, you deserve way more
how did you contact dani btw im trying to make a grapple hook game
I just dmed him on Discord :)
Affax when I did it was like, DELETED NOT FRIENDED :(
AGREED
i made the rope move in a circular motion by adding these lines, take a look if anyone interested
Script "GrapplingRope":
var right = Quaternion.LookRotation((grapplePoint - gunTipPosition).normalized) * Vector3.right;
var offset = up * waveHeight * Mathf.Sin(delta * waveCount * Mathf.PI) * spring.Value *
affectCurve.Evaluate(delta) +
right * waveHeight * Mathf.Cos(delta * waveCount * Mathf.PI) * spring.Value *
affectCurve.Evaluate(delta);
That's awesome to hear!
I always hope that people use this script and expand on top of it and this is just what I love!
Wow, I love the effect! Great job
were to paste it in grapRope
Wow that was really cool
Full Script With Edit For Anyone Who didn't understand how to do it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Grappling_Rope_Gun : MonoBehaviour
{
private Spring spring;
private LineRenderer lr;
private Vector3 currentGrapplePosition;
public Grappling_Gun grapplingGun;
public int quality;
public float damper;
public float strength;
public float velocity;
public float waveCount;
public float waveHeight;
public AnimationCurve affectCurve;
private float delta;
void Awake()
{
lr = GetComponent();
spring = new Spring();
spring.SetTarget(0);
}
//Called after Update
void LateUpdate()
{
DrawRope();
}
void DrawRope()
{
//If not grappling, don't draw rope
if (!grapplingGun.IsGrappling())
{
currentGrapplePosition = grapplingGun.gunTip.position;
spring.Reset();
if (lr.positionCount > 0)
lr.positionCount = 0;
return;
}
if (lr.positionCount == 0)
{
spring.SetVelocity(velocity);
lr.positionCount = quality + 1;
}
spring.SetDamper(damper);
spring.SetStrength(strength);
spring.Update(Time.deltaTime);
var grapplePoint = grapplingGun.GetGrapplePoint();
var gunTipPosition = grapplingGun.gunTip.position;
var up = Quaternion.LookRotation((grapplePoint - gunTipPosition).normalized) * Vector3.up;
currentGrapplePosition = Vector3.Lerp(currentGrapplePosition, grapplePoint, Time.deltaTime * 12f);
for (var i = 0; i < quality + 1; i++)
{
var right = Quaternion.LookRotation((grapplePoint - gunTipPosition).normalized) * Vector3.right;
var delta = i / (float)quality;
var offset = up * waveHeight * Mathf.Sin(delta * waveCount * Mathf.PI) * spring.Value *
affectCurve.Evaluate(delta) +
right * waveHeight * Mathf.Cos(delta * waveCount * Mathf.PI) * spring.Value *
affectCurve.Evaluate(delta);
lr.SetPosition(i, Vector3.Lerp(gunTipPosition, currentGrapplePosition, delta) + offset);
}
}
}
For anyone who cant get this to work. Dont skip any part of the video. I did so I missed the need to copy and past the spring script he created. its in the description if anyone else has the problem.
ok but where do I add the spring script
It isnt there tho
You don't add it to any object you just need to have it on your project as the main script relies on it @@hads4681
Very helpful!!! My initial grappling hook script worked a bit different but I managed to adapt this to my project!
I tried this and it reduced my FPS to about 10! I think this needs to be simulated in a shader for it be practical. Thanks for the tut though!
first thing when he drink milk i was like "oh shi# hes from finland"
Hey Affax thank you for the insights! The animation really looks beautiful!
Why do I know almost everyone in comments smh... BTW great video as always!
same.
same
CohexBruh same
Hey it's the wholesome mod
I am late to the party
You sir, just earned yourself a sub
I would like to have a little more explanation of why you're doing each change. Otherwise, great video!
Yea, I kinda tried to explain, but I hoped I was as good at explaining as coding.
I will try to improve that in future tutorials (if those even come) :D
@@Affax cheers mate, I'd really appreciate that! 👍👍👍
it looks like karlson ngl. oh, you don't know what karlson is? KARLSON IS JUST A GAME DANI IS WORKING ON, WE'RE TRYING TO GET TO NUMBER ONE ON STEAM SO SMASH WISHLIST, GAMERs!
You took something good and made it perfect. I thank you. Here take this subscribe
if somebody made a game based off of or even just using this grapple gun id be extremely intrested
this is frickin awesome!!!!!!!!!!!!!!!!!!!!
Milk gang for life
And can we use different colors instead of black rope
thanks man, you were the only one
Yes Affax
my line is going crazy it's normal for few seconds then it goes really really big
Did you get a fix for this?
@@TheJoker-cg6te not any I remember, but eventually I got it right, just mess with the settings a bit
affax "you should watch dani's movement and grappling gun tutoiral"
me "what would i watch before those theres only 2 videos :/"
@Hydro_Pixel i know its a joke :/
Yo affax voice(insert pog)
hello, this is a great tutorial i used this in several projects but i used it with danis script. and now i made my own graplle system and this is really hard to imploment.
man aproved good milk gang
Pirkka maitoa perkele
Thanks it works like a charm
Thanks! for the tutorial, really helpful
HOW DO YOU MAKE THAT BRIGHT BACKGROUND EFFECT
This is amazing
Which font do you use btw
I used either Inter or Roboto
And thanks for watching!
yo my game crashes when i use the grappling hook it says linerenderer.setposition index out of bounds! what do i do???
good tutorial thanks bro!
you deserve a like and sub bro
when i hold shoot, then it just becomes a really long line that's glitching up and down :/
the line for my line renderer is not appearing, how could i fix this?
Join affaxs discord server! Link in the description.
Error "line renderer.setposition index out of bounds" can anyone help me ??
Hi, great tutorial, it works very nice but I dont understand the formula you use in the Spring class. Can you tell what it's based on or some reference? I really want to know the math behind it.
how do you add the dot in the middle
"Do you want to create a awesome rope animation like this?"
No
Anger
@@Affax Hahoo
Affax I do though!
@@Affax yessss you helped me so much with this i was searching for a video like this and the fact that you used dani's grap gun script made this so easy for me thank you :D
DANI'S BROTHER?!
When i press play, it doesnt do it and i get this error:
Invalid editor window UnityEditor.CurveEditorWindow
UnityEditor.EditorApplicationLayout:FinalizePlaymodeLayout ()
what does this mean?
my affectcurve isn't working
I am working on a game and I set it up to make it so that it is right click and left click but it wont let me put the right click gun in the script so I am unsure of what to do
Did anyone notice that he has minecraft Launcher pinned to his Taskbar 😂🤣
(BTW thx for the advice👍)
So?
Drink Reveal - 2020
when I put the script its done properly but when I use the grappling gun it puts the error linerenderer vector 3
ig its Vector3 not vector 3 its caps sensitive
I don't now why but my rope is VERY affected by FPS so I need to decreese velocity when FPS is low
I like how no one noticed the bud light in the sink
Good eyes! xD
Thanks lol
How can i make some motion after it reach to the point i mean 1 he throw the rope and 2nd effect after it reach the point ...
is it possible ?
hi, it is working amazingly and i only have two questions. 1. when i get too close to where i pinned the rope to it starts pushing me away 2. if i were to make it so if i pressed space it would draw me in, how would i go about doing that? Thanks!
Hi! To avoid being pushed away:
joint.minDistance = 0f;
To press spacebar and have it draw you in, put this in your void Update() under everything else:
else if (Input.GetKeyDown(KeyCode.Space)) {
joint.maxDistance = 0f;
}
else if (Input.GetKeyUp(KeyCode.Space)) {
joint.maxDistance = 20f; //put whatever you want the "normal" distance to be here -- the distance when not reeled in
}
Hope this helps! If I can clear anything up for you, let me know!
@@-BRODEN is there a way to make the joint.maxDistance the current position you are in or the joint.maxDistance to be the position you grappled from? if there is, i would like to now but if there isnt, its totally fine
I FUKIN LOVE YOU
WOW
You Are Really Coooool
my grapplingrope spawns in a rigidbody?
ayyyyyyyyyy a finnish man im finnish to
Ayy nice to hear!
Hi im getting an error that says "LineRenderer.SetPosition index out of bounds" and it brings me to the line "lr.SetPosition(i, Vector3.Lerp(gunTipPosition, currentGrapplePosition, delta) + offset);" do you know what the issue could be?
It's probably because you missed one line or forgot to set the quality to something above 0: github.com/affaxltd/rope-tutorial/blob/f40f4cd095602e158b6ff43d594aa0b9622f864a/GrapplingRope.cs#L41
@@Affax Hey man I got a error saying Invalid editor window of type: UnityEditor.CurveEditorWindow, title: Curve
UnityEditor.EditorApplication:Internal_CallDelayFunctions () and I copied everything from github, pls help.
my frame rate dies and I get an error that says LineRenderer.SetPosition index is out of bounds please help
Good now where is the irl tutorial hmm?
IRL tutorial coming 2025
shit
Thanks dude!, but I kinda need it for 2d... But still cool! :D
Where is the Milk Gang
Well it works, but now all my UI elements are black for some reason. Why?
nvm, i restarted unity and the bug is fixed. Thanks for the tutorial! The effect looks awesome!
wow make more tutorials please
dood thek yu su mech!
I want to ask how can i add something Like lightning into that rope Like its neon rope please help
if you want you can use brackeys light video and add it to the rope tho i haven’t done that but the role is a physical object so it should work
thank you
Hello, nice video. Whenever i try to grapple onto something, it creates a straight line with your curvy one. Is there anyway to fix this or have I missed a part of this video?
Hello, I had the same problem, copying his code and pasting all of it (all scripts) fixed it for me
@@octopro8937 Ty. I will try that out sooner or later.
can you do a project files with the character and level and scripts too please it doesnt work for me
hey could i use this in my game?
of course! you're free to use it in anything you want
i need help. i got the wobble working but it only works if i select the grapple gameobject in the hierarchy.
nevermind fixed it. i just had to put all the scripts on the player.
My animation isnt working can anyone help? when i click play nothing happens
Karlson test 2.0
Huh my rope doesn't show up
Edit: guess I forgot a piece of code, went and change the code with yours by copy and pasting
Hey! Thanks for the tutorial! My rope is becoming very big if I press and hold, how can I prevent that?
Dude,danis wall run pls
how do i get the grapplingrope script
Hey! I was just wondering what do you use to type code? It doesnt look like Visual Studio?
I use Rider to code, it's an IDE from Jetbrains! It's not free, but if you're a student like me you get it for free.
Nice vid, but the thing is that ive made my own grappling script, and when I see this tutorial it is totally based on Dani's script, so it is hard to adapt to any other script
Well, it does make sense, I cannot really make a tutorial for each grappling hook implementation as the way people hand the rope is very different, though, in the future I might look into making a modular one where you just call start and end functions, we'll see.
Hopefully the spring script and the changes to Dani's scripts help you integrate it into your own scripts though!
@@Affax Yeah I see. I managed to implement it now even if that was quite hard. I think the thing the made it complicated is that you didn't really explained how did you come to put some lines where they were. But I understand that you can't explain everything because it would make it too long haha. Anyways your video is still super usefull so yeah that's cool
@@slyzrl1361 i want to make a rope like sekiro like the way he trow the rope Do you got any helpful material or suggestion how can i make it ? for now i have used this code for throw and removed player movement tho only my rope is throw now.. If you Help Thx...
Milk made me just sub
LineRenderer.SetPosition index out of bounds!
UnityEngine.LineRenderer:SetPosition (int,UnityEngine.Vector3)
GrapplingRope:DrawRope () (at Assets/Character/GrapplingRope.cs:59)
GrapplingRope:LateUpdate () (at Assets/Character/GrapplingRope.cs:26)
skybox download? i really like it
It's linked in the description
gun
🔫
i cant find any gun emoji, but i found a squirt gun
@@exaltation6851 thank you this is epic
Am Dani Fan Yupsi Pupsi
what object should i aply spring script?
You don't need to apply it to anything
MILK GANG YES
Why is my rope going crazy and also back to origin? HELP
Same with mine, did you get it to work?
Did you get a fix for it? My rope also becomes very big if I hold it for too long.
OMG SUOMIIII
perkele
How do u get the sight type thing so u can see where ur shooting
I created a canvas and added a square image in the center.
@@Affax thankyouuuu
Hey great tutorial well explained but when i go back to unity i get the error”Update function can not take parameters” any advice?
Check your code against the code in the description, and you'll probably find the error there.
Thx alot i managed to find the error
Great results keep the work up
my rope is not visible pls helppp
how do i make it pull me closer with more power?
higher the spring number in grappling gun script
Share all this project please, in my something not work)
I could use make ODM
what object do i attach the spring script to?
You actually don't attach it to anything! It's just a utility script that we used in the code, so it requires no extra setup.
@@Affax Ok!
I did everything according to the video but the rope has no animation and after the shot, the whole game starts lagging I don't know what to do with it. Can you help me, please?
damn i got tricked...
i was half way done coding the spring script, but then i realised that u have a ready script at github...
i deleted my spring script and copy pated the RAW Paste Data...
I got tricked and now i lost all of the script i wrote...
i can't dude... it's 11:31pm and i have to finish my school project before tomorrow... and im not even half way there with programming my game.. Could someone PLEASE paste the "GrapplingRope" script?
WHy did u dellte the weapon Manager tut
It wasn't as good as I wanted. I also didn't know a whole lot about RUclips, so I just unlisted them. But I decided to redo the grappling video with more effort and skill put into it.
I can't seem to get this to work in 2D. How would I?
It's not meant for 2D so I have no idea. I've personally not made 2D games in years.
@@Affax Hi! I got it to work in 2D with a little bit of tweaking.
One problem I'm having is that the end of the grappler is lerping, its not fixed at the grapple point, its smoothly following it.
@@JacksonAcademy1 Awesome to hear man! Yeah, 2D in Unity is close to 3D from what I hear, but due to lack of my skills in it I couldn't help. Thanks for watching the tutorial, hope it helped!
@@Affax Both the end point, and the start point for the grappler are moving.
no errors come but the wave isnt coming when i play
fixed it
@@rdev3720 how
@@Dynks90 I deleted the project like 10 months ago
I was tryna remake karlson but now I learned that making projects I enjoy is more important
@@rdev3720 sad, but you should do what you prefer
bred
bred
bred
*im cookie*
@@achille.g shut
One question : Does this script that you made comes with Grappling Gun too?