Тёмный

How To Make Any Game Mechanic - Episode 7 - 2D Grappling Hook 

ThatOneUnityDev
Подписаться 6 тыс.
Просмотров 6 тыс.
50% 1

Опубликовано:

 

7 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 41   
@ThatOneUnityDev
@ThatOneUnityDev 11 месяцев назад
Don't forget to leave your suggestions in the comments! :)
@migcreatesgames2622
@migcreatesgames2622 11 месяцев назад
I am liking the episodes. Good stuff
@ThatOneUnityDev
@ThatOneUnityDev 11 месяцев назад
Glad you like them! :)
@niyamshah8091
@niyamshah8091 9 месяцев назад
Rlly cool idea - is it possible to choose the grappling hook direction using button inputs - like arrow keys Also a suggestion that could be cool - character switching mechanic - 4 different characters that can be switched between with different moves each Each character would have different sprites/ abilities and movements Sortof like pyra/mythra from super smash bros ultimate
@ThatOneUnityDev
@ThatOneUnityDev 9 месяцев назад
You definitely could! If you look at our raycast overloads, instead of shooting a ray from the mouse, into the scene.; You could shoot one from origin player, with some maximum distance, in the input direction. Character switching could be really cool! I will add it to the list! :D
@niyamshah8091
@niyamshah8091 6 месяцев назад
@@ThatOneUnityDevI recently tried this but I keep getting stuck on setting the origin - I’ve tried many different methods but am unsure how to go about this? R u able to spare some advice
@ThatOneUnityDev
@ThatOneUnityDev 6 месяцев назад
​@@niyamshah8091 No problem! So, from what you've said before, you wanted to have the grapple hook use arrow key input. What you will need to do is get a direction relative to the player, based on input. For the raycast, change the origin to be the player's position, and the direction to be the direction you calculated. You would also want to change the input to probably not the mouse. So, overall, not too many changes. lol. I typically don't do this, and don't advise asking others, but seeing as you came back here to ask for advice again, 3 months later, I have taken the liberty of implementing my advice. Here is a pastebin file, with working code, that implements all of the above! I highly suggest taking a good look at it, and understanding what was changed! :) pastebin.com/gDG7Rrfa In this example, I have drawn the input direction in red in the inspector, to show the direction the grapple will shoot. As a side note, I still suggest extending the logic, to implement features that dynamically change the grapple length for a 'better' grapple hook.
@Soundy777
@Soundy777 11 месяцев назад
Ayooo!!!!! \o/ Very cool use of the DistanceJoint2D component!! Next Suggestion:: SPIKE TRAP!
@ThatOneUnityDev
@ThatOneUnityDev 11 месяцев назад
Glad you liked it! :) ... Nice! I will add it to the list! :D
@krishnarai4854
@krishnarai4854 11 месяцев назад
I would love to see a bat physic. Even when you change the bat position, it still swings when clicking the button. I just started learning unity and i made the bat swing with pivot point but as soon as i change the bat position, it stops working and starts to teleport
@ThatOneUnityDev
@ThatOneUnityDev 11 месяцев назад
I will add it to the list! :)
@AxxoraZop
@AxxoraZop 5 месяцев назад
I also added an background but i cant see rope if i add background but when i remove it shows
@ThatOneUnityDev
@ThatOneUnityDev 5 месяцев назад
Must be your sorting layers on the line renderer, and background sprite!
@MLTWNight
@MLTWNight 3 месяца назад
heya, thanks for the tutorial. i have an already established character controller and everything including guns. I did exactly everything, changed few stuff here and there, no matter what i do i cant make it work. i debugged a bit, it reads the mouse click input, returns null value on "hit", sometimes boxcollider on the objects, does not grapple, but moves the character in a weird way. im a bit confused, any clue what could be the problem?
@ThatOneUnityDev
@ThatOneUnityDev 3 месяца назад
It sounds like maybe your grapple layers aren't setup correctly, or maybe interference from other scripts. I recommend basically doing what I did just for testing purposes. Have a square with a box collider2d, and rigidbody2d. Then, add just the grapple script. If that works, slowly add each script until you find the culprit. Hopefully it's just as simple as fixing your layers though. 🤞
@MLTWNight
@MLTWNight 3 месяца назад
@@ThatOneUnityDev sadly it wasnt the layers, but in the end your tutorial let me think of a completely different mechanic xD thanks man, cheers!
@honblb100
@honblb100 3 месяца назад
Very useful video! Thanks so much. I replaced the distance to the distance of the mouse to the cinemachine camera, but it doesnt collide with objects.. Can anyone help?
@honblb100
@honblb100 3 месяца назад
I figured it out!! I just needed to enable collisions at the distance anchor. Really helpful tutorial though! Keep making good quality videos like this one!!
@rabidcheesemonkey1092
@rabidcheesemonkey1092 29 дней назад
For some reason, this only works if I set the Grapple Layer Mask to default. I set it to anything else and it won't work. Did I set something wrong?
@ThatOneUnityDev
@ThatOneUnityDev 29 дней назад
Hi there, thanks for watching! A couple of things could be happening here. I would first ensure that the grapple layer mask and the object you want to grapple to are BOTH set to the same thing. For example, the ceiling layer. You may have accidently created a layer, but didn't actually set your object to it. The problem with raycasts is that you can also accidently 'block' the object you're trying to detect. This should be solved with the layer mask, but just for arguments sake, try ensuring you don't have overlapping colliders where you're trying to grapple to. Hopefully this helps! 👌
@bcoda
@bcoda 11 месяцев назад
cool can you do it in Godot
@ThatOneUnityDev
@ThatOneUnityDev 11 месяцев назад
I didn't think the channel was called ThatOneGodotDev 😂
@DarkerCry
@DarkerCry 11 месяцев назад
It's a good challenge to recreate mechanics in an engine you like, I often try and recreate things in Flax. It'll help you learn the engine you like and have a better understanding of the mechanic (imo).
@benjamins.nielsen1843
@benjamins.nielsen1843 2 месяца назад
Is there a way to add like a max range on the hook?
@ThatOneUnityDev
@ThatOneUnityDev Месяц назад
Absolutely! In the same if statement we check if there is a valid collider, we would also use something like Vector3.Distance, and compare the players position to hit.point. This would prevent the grapple from working unless the player was close enough to the grapple point!
@anikahedden6057
@anikahedden6057 2 месяца назад
It is possible to do with a different collider such as a composite collider or tilemap collider? I've tried having everything on the same layer but it doesn't seem to work
@ThatOneUnityDev
@ThatOneUnityDev 2 месяца назад
@anikahedden6057 Yeah for sure! It should work with any type of collider you can think of. :)
@anikahedden6057
@anikahedden6057 2 месяца назад
@@ThatOneUnityDev wow thanks for the fast reply! I figured out the collider but now I'm having trouble changing the speed of the grappling hook. I find that I'm flying up to the ceiling way too fast. any way I could find a fix?
@ThatOneUnityDev
@ThatOneUnityDev 2 месяца назад
@anikahedden6057 Haha, no problem! I'm glad you got it working! Unfortunately, with this method, we are letting the joint do all the work for us. So when it comes to tweaking things like speed, we don't really have that option! What I would recommend is to move the player to the grapple point via code, then create the joint. That way, you can have much more fine-tuned movement!
@Greeny_Official
@Greeny_Official Месяц назад
@@anikahedden6057 What was your fix for the collider? i think I'm currently having the same problem...
@stellarscopeyoutube
@stellarscopeyoutube 4 месяца назад
can you help me how to low the speed when i hook, it goes really fast, not naturally.
@ThatOneUnityDev
@ThatOneUnityDev 4 месяца назад
In this quick example, we are using the joint to move the player. Therefore there is no "speed" variable we can play with. I would suggest manually moving the player to the destination, and only after he reaches there, enabling the joint. By doing it this way, you will be able to control exactly how fast/slow you want him to be.
@mykull8465
@mykull8465 4 месяца назад
@@ThatOneUnityDev Hey how would you go around actually moving the character to the point, I tried using vector2.movetowards but it just doesnt move towarsd the character, thanks
@Itaisss
@Itaisss 21 день назад
@@ThatOneUnityDev Any tips or advice on how to do that?
@ThatOneUnityDev
@ThatOneUnityDev 20 дней назад
@@Itaisss For sure, no problem! By using the raycast that we already have (that is checking if there is a valid grapple point). We can easily grab the exact spot we clicked by using hit.point. From there, we would have a desired position (the spot we clicked). And that's pretty much the hardest part. So with our newly found desired position, we can subtract the vectors of that, and the player - and grab the direction of that desired position. Then it's as simple as moving the player along that direction, with some sort of speed constraint. Then, when he get's however close you like, enable the joint as we were doing before. I know all of that sounds maybe a little complicated explained via text, but if you take it step by step, i'm sure you will get there! :)
@Itaisss
@Itaisss 20 дней назад
@@ThatOneUnityDev I got it working after a lot of errors 🤣 thank you so much!
@malserAI
@malserAI 6 месяцев назад
yo, you are "Code Monkey"?) your voice is identical :D
@ThatOneUnityDev
@ThatOneUnityDev 6 месяцев назад
Haha, i'm not code monkey, but i'll take it as a compliment! :)
@malserAI
@malserAI 6 месяцев назад
@@ThatOneUnityDev ahaha 🫡🫡🫡
Далее
How to Make a Good 2D Camera
11:38
Просмотров 402 тыс.
Я ЖЕ БЕРЕМЕННА#cat
00:13
Просмотров 231 тыс.
Giving Personality to Procedural Animations using Math
15:30
I Made the Same Game in 8 Engines
12:34
Просмотров 4 млн
The Trick I Used to Make Combat Fun! | Devlog
8:12
Просмотров 1,6 млн
Optimizing my Game so it Runs on a Potato
19:02
Просмотров 566 тыс.
Attempting to Learn 3D Game Development in One Week
11:10
What size should your assets be? | HD 2D GAME ART
12:10
The Most Impressive Scratch Projects
11:00
Просмотров 4,9 млн