How to make a 2D Bow and Arrow with UNITY & C#!

Поделиться
HTML-код
  • Опубликовано: 19 дек 2024

Комментарии • 326

  • @tarkozkan6439
    @tarkozkan6439 4 года назад +21

    If you want to change the launchForce according to mousePosition you can remove public from launcForce and write launchForce = Vector2.Distance(shotPoint.position, Camera.main.ScreenToWorldPoint(Input.mousePosition)); in the Update function

  • @astropolski
    @astropolski 4 года назад +41

    8:57 you dont need to do == with bool if statement like "if (bool == true)" you can just do "if (bool)" for true and "if (!bool)" for false
    edit* nice to have you back, haven't seen a vid from you in a while :)

    • @sjohncreations4369
      @sjohncreations4369 4 года назад +10

      Sometimes it helps to understand the code, even if it's redundant

    • @gamedevhq
      @gamedevhq 4 года назад +1

      wrong. code won't compile.

    • @haemogoblin7006
      @haemogoblin7006 4 года назад +11

      @@gamedevhq i hope u get that when he said 'bool' he was referring to that particular boolean identifier and not the keyword bool

  • @abdo9390
    @abdo9390 4 года назад +124

    Liam sounds alot like noa. It took me time to notice 😂

    • @toby_1405
      @toby_1405 4 года назад +5

      B A u are right man!

    • @eyeprops5422
      @eyeprops5422 4 года назад +3

      I know right? Liam should use a batman voice... lol. The switch was almost seamless.

    • @hypehextech4680
      @hypehextech4680 4 года назад +1

      well, they are brother after all!

    • @WingerWind
      @WingerWind 4 года назад +3

      They have the same accent, and similar ways of speaking, but Liams voice is higher.

    • @WhatABlankName
      @WhatABlankName 4 года назад +2

      There freaking brothers duh, lol but yes they do sound alike

  • @ninjaboyjames
    @ninjaboyjames 4 года назад +30

    Welcome back teacher.

    • @Blackthornprod
      @Blackthornprod  4 года назад

      Glad to be back !

    • @rdev3720
      @rdev3720 4 года назад

      blackthornprod is it possible to create a stationary enemy that shoots projectiles after 1 second if so how? Please respond soon.

    • @haemogoblin7006
      @haemogoblin7006 4 года назад +2

      @@rdev3720 of course its possible, i just hope i'm not late (even tho the question isnt directed towards me T - T)
      you cud achieve that effect using coroutines or you cud make ur own timers! Check this out - answers.unity.com/questions/1108438/how-to-instantiate-prefabs-at-certain-times.html

  • @prithviproduction4412
    @prithviproduction4412 4 года назад +78

    There is almost no difference between noa and liam

  • @eyeprops5422
    @eyeprops5422 4 года назад +1

    HOORAY! Thanks for this. I was one of people that requested it. You shall be rewarded by the Game Gods.

  • @hypehextech4680
    @hypehextech4680 4 года назад +27

    glad to see Noa is still alive, as he hadn't uploaded for a almost 2 months 😂

  • @jorgevital89
    @jorgevital89 3 года назад +2

    You guys always make these tutorials so easy to understand. Thanks!

  • @Blaze2992
    @Blaze2992 11 месяцев назад

    I barely understood any of this but seemed to work in the end. Cheers for the tutorial

  • @praadiiit
    @praadiiit 4 года назад

    You guys getting better by the time

  • @theHaPK
    @theHaPK 4 года назад

    When calculating position of points it would be beneficial to reuse position of previous point, that way you will need to do less calculations overall. So, instead of creating a function that calculates position based on time, you factor in everything into the loop and reuse state between iterations.

  • @sathvikmalgikar2842
    @sathvikmalgikar2842 2 года назад +1

    god level physics and game concepts!

  • @junglejim6674
    @junglejim6674 4 года назад +12

    Thanks for the video guys, appreciate it and it helped me a lot. However there are 2 issues I ran into. First, when the arrows gets stuck in an object, and for instance enemies run into them, they continue to take damage from collisions with the arrow. This I fixed by disabling the collider. Second, if you'd like the arrow to follow the game object it sticks to, parent it to the collided object.
    2 lines of code fixed these issues for anyone else in the same situation:
    After applying damage, in the OnCollisionEnter2D method:
    gameObject.GetComponent().enabled = false;

    // Arrow no longer collides with other
    objects after first collision
    transform.parent = collision.transform;
    // Arrow follows collided object
    Again, thanks and hope this helps someone else!

    • @Shrink_Assault
      @Shrink_Assault 4 года назад +1

      Thanks

    • @syfenw6586
      @syfenw6586 Год назад

      @junglejim6674
      how did you make it do dmg to enemys

    • @Tweakyowl
      @Tweakyowl Год назад +1

      I love you so much. I'm just 3 years late.

  • @NicDev
    @NicDev 4 года назад +8

    Finally! The master has return, and this is what i need from a long time for my game

  • @NeatGames
    @NeatGames 4 года назад +8

    I would love a tower defense udemy or youtube tutorial :D

    • @Blackthornprod
      @Blackthornprod  4 года назад +3

      We will think about it !

    • @MiloTheDuck-s7j
      @MiloTheDuck-s7j 4 года назад +1

      Hi Neat games Lol I found you XD

    • @NeatGames
      @NeatGames 4 года назад +1

      @@MiloTheDuck-s7j Oh hello :D I still want to learn how to make a Tower Defense game haha.

  • @echratus
    @echratus 3 года назад

    Was watching the 2d ranged weapon tutorial didnt understand a clue what the mouse following code meant came here and i understand that code now lol

  • @Dmcc1942
    @Dmcc1942 4 года назад +5

    Can anyone tell me if you use the paid for photoshop or the free Express one?
    If you dont use either can you tell me what you use ?

  • @hiimandrew.
    @hiimandrew. 4 года назад +5

    I love this video man! And I haven't even seen it yet! : D

  • @ninjabuilder691
    @ninjabuilder691 4 года назад +1

    Hey! great to see you back!

  • @maistrogaming7911
    @maistrogaming7911 4 года назад

    Fine.....ffffff I missed those videos....finally ..I was waiting until this video XD...but yeah please continue your serie I want to learn from you

  • @abhinawram4014
    @abhinawram4014 Год назад +1

    Is there any way to make line renderer length limit ?
    line renderer endPos follow mouse position but line length goes infinite want line length limited.

  • @Xadness22
    @Xadness22 4 года назад +2

    Yay my man noa is back.
    I really have fun at your udemy course.
    This 2D strategy game is literally awesome. You guys make the project to expansive project. Really worth to check out guys.
    Really thankful to noa and Liam for amazing course,and free tutorials!

  • @ajwahtoonz2688
    @ajwahtoonz2688 4 года назад +1

    dude,I love your tutorials they are very useful

  • @TheUltiCAKE
    @TheUltiCAKE 4 года назад +2

    Thanks so much, This helped a lot, I searched drastically for a tutorial for this and yours was by far the most effective and simplest.
    Quick Question: Is there a way to stop the dots from showing after they collide with a platform, so that you never see the dots beyond the platform that it hits?

  • @filipjovanovic7693
    @filipjovanovic7693 4 года назад +5

    Hello Blackthornprod, i love your videos and because of them will get into game dev. I wanted to ask is starting to learn unity at 13 years old late?
    Thanks again for inspiring me to get into game development

    • @Anerisian
      @Anerisian 4 года назад +3

      Yes, you’re too old. Most devs begin when they are younger than 5 years old.
      Just kidding, you will never be too old to learn anything. And it is never too late to learn anything. However, things can be easier or harder at different times.

    • @filipjovanovic7693
      @filipjovanovic7693 4 года назад

      Haha you scared me for a second

    • @mbcchoudhari885
      @mbcchoudhari885 4 года назад +1

      @@Anerisian thats some real observation and motivation

    • @taleofrealitydeveloper2147
      @taleofrealitydeveloper2147 4 года назад

      İ started at 10 -_-

    • @Blackthornprod
      @Blackthornprod  4 года назад +1

      No you are starting very early, that's great ! We started later than you ! You are very welcome !

  • @Oscar-lp6zd
    @Oscar-lp6zd 2 года назад

    Incredibly helpful tutorial - thanks both of you :)

  • @user-kdjalkdsjfoiwef
    @user-kdjalkdsjfoiwef 3 года назад +1

    I used google translator
    Why multiply 0.5 by gravity and add it?
    And do you square the time here?
    Are there any resources to understand the formula?

  • @maddened3746
    @maddened3746 3 года назад

    4:20 my object doesnt move with the cursor at all

  • @simoncodrington
    @simoncodrington 4 года назад +1

    Nice video guys, keep it up :)

  • @crgamedev734
    @crgamedev734 4 года назад +4

    Could you make a tutorial on how to draw, the style you have in this tutorial

  • @nileshkumawat6730
    @nileshkumawat6730 2 года назад

    You are very helpful at all time for me😄

  • @alexthekidmg
    @alexthekidmg 4 года назад +1

    How would you make it so that launch force changes depending on how far the mouse is from the bow with a restriction on it?

    • @squash_boi901
      @squash_boi901 4 года назад +1

      in the Shoot method, you would multiply the velocity of the arrow by the distance between the mouse position and the bow position, and then clamp it between two numbers

  • @playingcoding5045
    @playingcoding5045 4 года назад

    Great Video! Thank you. Just started my own video series developing a procedural generated 2d rpg with Unity. :)

  • @amirrezarabani7861
    @amirrezarabani7861 7 месяцев назад

    Thank you so much for always helping me❤❤❤❤

  • @FernandoPosserPinheiro
    @FernandoPosserPinheiro 2 года назад

    Great tutorial! Thanks for sharing (:

  • @tatebinkey7935
    @tatebinkey7935 4 года назад +1

    What is the song called at the beginning of the video? Thanks

  • @TK-sr2hz
    @TK-sr2hz 4 года назад

    Liam's actually my math teacher

  • @datboijoshki8833
    @datboijoshki8833 4 года назад

    Thanks so much I've been Searching for this

  • @filipv3175
    @filipv3175 Год назад

    hey men i have trouble using transfrom any gues? The type or namespace name 'Transfrom' could not be found (are you missing a using directive or an assembly reference?)

  • @nocontexthuman6103
    @nocontexthuman6103 4 года назад +1

    This took a lot of time to see your new video Noah!

  • @mehmeh8883
    @mehmeh8883 4 года назад

    Now this is some original BTP content!

  • @perssontm1628
    @perssontm1628 4 года назад +1

    When i move my sword gfx (child object) my empty game object (the parrent) follows so i can't set my pivot point, any fixes?

  • @bukasker9051
    @bukasker9051 2 года назад

    Realy good tutorial it helps me a lot

  • @mohammednihad6755
    @mohammednihad6755 4 года назад

    Finally making tutorials again :)

  • @ankitpatel0101
    @ankitpatel0101 4 года назад

    Thank you very much.
    Such a nice tutorial.
    🏹

  • @wearwolf4202
    @wearwolf4202 Год назад

    How would you make the line thing for an a.i? Id like to show the user where the enemy is aiming before it attacks. Any help would be appreciated love your work

  • @Demon-lv7mc
    @Demon-lv7mc 3 года назад

    i love your tutorials

  • @arcday4281
    @arcday4281 4 года назад +7

    We need more lessons on unity 2d... "HOW TO MAKE"

  • @hofnarrhanswurst5278
    @hofnarrhanswurst5278 4 года назад +3

    And the links to the courses are of course INDIE description xD

  • @thedevine3756
    @thedevine3756 4 года назад +1

    Can you do tips and tricks on how to make a game look as good as yours do? :)

  • @mehmedcavas3069
    @mehmedcavas3069 4 года назад +1

    A tutorial after years 😄

  • @Codejoy
    @Codejoy 4 года назад +1

    Fun tutorial, has anyone gotten this to handle the fact if you are moving with arrow keys and pressing left faces the character left with the local scale .x to -1 ? If I face right it all works, if I turn left it is all off on the math, ideally the bow wouldn't even care what direction the player is facing but not sure how to make that happen sinced the Bow game object is a child of the parent.

  • @crgamedev734
    @crgamedev734 4 года назад

    Finally you made a tutorial about using unity, good luck with your game!

    • @zahhym
      @zahhym 4 года назад +1

      Hes made like a billion

    • @crgamedev734
      @crgamedev734 4 года назад

      @@zahhym I know but I'm talking about in a long time

    • @Blackthornprod
      @Blackthornprod  4 года назад +1

      Thanks !

  • @sonitarang1
    @sonitarang1 4 года назад +1

    I didnt understand the position formula that you used for the dots

    • @hrishikeshgarud7177
      @hrishikeshgarud7177 4 года назад

      I also. How the velocity in Newton formula change to distance in unity

  • @surajeswaran635
    @surajeswaran635 4 года назад +1

    Hey! Thanks for the tutorial. This is a super useful tutorial. I have an idea for a challenge. As you are very good at making games, how well can you make a game in scratch? It can just be a quick and easy challenge. Thanks for the tutorial!

    • @Blackthornprod
      @Blackthornprod  4 года назад

      It's our pleasure ! we will think about it

  • @PeterMilko
    @PeterMilko 4 года назад

    Pretty cool dude. How did your game do?

  • @taylorhugins5787
    @taylorhugins5787 3 года назад

    This is almost exactly what I needed, how would I go about showing the proper trajectory if I want my bullet to bounce off of objects? Right now the line goes right through objects with colliders even though the bullet itself is bouncing off of them.

  • @mikael808
    @mikael808 4 года назад +2

    Hi Noa, first of all, thanks for the awesome content you make! And my question is can this be used to mobile games also? Thanks! :)

  • @alphabowzer1253
    @alphabowzer1253 3 года назад

    Hey man, I was wondering how you would get an arrow to spin(like a throwing knife)? Thanks!

  • @uiteh7036
    @uiteh7036 Год назад

    you are probably never gonna answer to this, but, how would i go about making the "shooting prediction" stop when colliding with objects?

  • @sspyrshlsx3740
    @sspyrshlsx3740 4 года назад +1

    I bet you love pronouncing that _Blackthornprod_ intro

  • @FFalanFilan
    @FFalanFilan 3 года назад

    Hi Guys. Vector2 position =(Vector2)shotPoint.position + (direction.normalized * launchForce * t) + 0,5f * Physics2D.gravity * (t*t); the error says '+' , cannot be applied to 'Vector2' and 'int'. something like this. I used brackets but did not work. Any suggestion ?

    • @FFalanFilan
      @FFalanFilan 3 года назад

      It is ok. I solved.

    • @tubyuwu2320
      @tubyuwu2320 Год назад

      @@FFalanFilan how did u solved?

    • @FFalanFilan
      @FFalanFilan Год назад +1

      @@tubyuwu2320 I have not done anything in unity for a long time. But i will try to check the software if ı did not delete the unity itself.

    • @tubyuwu2320
      @tubyuwu2320 Год назад

      @@FFalanFilan thanks

  • @guildmastersstory2169
    @guildmastersstory2169 3 года назад

    So this vids 11months old but figure I’ll ask anyway. What would be a good way to code it so player input can affect velocity and therefore trajectory? Was thinking something like holding the key down longer, makes the shot faster/straighter.

    • @thetra00
      @thetra00 3 года назад

      you would need to multiply the Velocity or Force with time the button is pressed.... well how to code is up to you ^^

  • @DanielLochner
    @DanielLochner 4 года назад

    Awesome work Noa and Liam! You guys make a great team! :)

  • @endfire7715
    @endfire7715 4 года назад

    Hey Noah and Liam I hope you guys see this because I need help. I am trying to do the Game Tiny Planets with your Tutorial but it isnt working when i am trying to do the play button. Do I have to create the button in the play image tab or in the Canvas because when i create the Button in the image tab it isnt working and when i create it in the Canvas it is working but the play button is HUGE

  • @spacewhiffle5344
    @spacewhiffle5344 4 месяца назад

    what is the "f" in 0.5f? thx for any help in advance

  • @manusia3776
    @manusia3776 3 года назад

    Sorry I'm a little bit late here. But I want to ask, is it possible if the pointer doesn't go through a collider/wall

  • @elpepsi781
    @elpepsi781 Год назад

    This helped so much!

  • @ajitkumargovindaraj7440
    @ajitkumargovindaraj7440 3 года назад

    That was really awesome:)...Somehow can you pls give me piece of advice to make projectile collide .. it's actually overlapping objects.. Thanks in advance..

  • @yousifsuleiman7613
    @yousifsuleiman7613 4 года назад

    I am very very happy to see again noa´s tutorials 😍😍😍😍
    plz do more and soonly😭

  • @hypermuffin84
    @hypermuffin84 3 года назад

    Is it possible to join the ranged combat script to this script? i'm trying to make a universal shooter for future games

  • @pixspaces4777
    @pixspaces4777 4 года назад +1

    Nice to see you back again Noa.. also Liam sounds a lot like you! Good video btw will definitely implement this in a future project..

  • @Xadness22
    @Xadness22 4 года назад

    Yay our man noa
    I am really have fun in your strategy 2D course !Guys this strategy game is really fun and worth to buy. Literally amazing 😍.I bought topdown shooter too but I haven't done yet cause I literally have fun at 2D strategy game. Really really cool.Love u bro noa and Liam 🤩🤩

  • @TheVulaj
    @TheVulaj 4 года назад

    how can i make to shoot withaut rotation but in direction the player is walking
    i cant shoot on the lef side only right

  • @In-N-Out333
    @In-N-Out333 4 года назад +2

    When setting the rotation, use rb.rotation instead of transform.rotation; this is guaranteed to be the actual position of the body. Transforms are not for the physics system; they're for everything else, like animations, etc.

  • @gamesplusjames
    @gamesplusjames 4 года назад

    Cool tutorial guys! :)

  • @SkelleRok
    @SkelleRok 4 года назад +1

    Wow. Liam explained pretty heavy stuff in an easy and light way. Would like more videos like this.

  • @jamsdem2311
    @jamsdem2311 4 года назад +1

    This is awesome dude!! Now I know how to make a bow power up in a platformer if I ever wanted too.

  • @fabianschmidt6850
    @fabianschmidt6850 4 года назад

    do you use a special program for creating and drawing these cute sprites?

  • @giorgioguglielmone6528
    @giorgioguglielmone6528 4 года назад

    Hi, interesting tutorial. If I wanted to move a 2D character according to the pointing direction of the mouse (without clicking) and moving the character only at the press of a button (for example W), how can this be done ? Have you already done a tutorial on this topic ?

    • @haemogoblin7006
      @haemogoblin7006 4 года назад

      u cud use MoveTo function or get the mouse position, as they did in this video, and use transform.translate or use the character's rigidbody and give it some velocity along the direction of (mousePosition - characterPosition) or something... it need not necessarily be as brief as i mentioned but is sure easy to understand

    • @jarrettonions3392
      @jarrettonions3392 Год назад

      Did you figure it out? You would use something similar, find the angle. Find the distance between the mouse and character. Set your velocity, or add force as distance x movement speed in the direction

  • @tobiasnilssenopedal6660
    @tobiasnilssenopedal6660 2 года назад

    If i would add delay between the shots, so that the player just cant spam shoot. How would i do that?

  • @phillipsmith3038
    @phillipsmith3038 Год назад

    So I followed the steps but it's not creating any arrows. I can see them being created in the sample scene but not in the actual game. Any idea as to why?

  • @genib6174
    @genib6174 4 года назад

    May I ask why not just set the rotation of the arrow to it's normalized velocity vector?

  • @damar126
    @damar126 3 года назад

    Thank you, man!

  • @flashbackmovie8792
    @flashbackmovie8792 3 года назад

    please tell me how to turn off the trajectory of the arrow

  • @765Kuma
    @765Kuma 4 года назад

    Hey Blackthornprod, I just discovered you today and I'm loving your content. I don't know if it's a recent change but the Udemy courses seem to be $50 dollars instead of $10. Was this only a limited-time sale?

  • @mazuchi5271
    @mazuchi5271 4 года назад

    Any idea about boomerang script !

  • @aspenpawarts9333
    @aspenpawarts9333 4 года назад +3

    Hey dude! Unrelated to the vid but could you consider putting some of your games on the switch E- shop? They would be great for it, would bring in some extra money and the switch needs it rn. The e shop is full of trash. Idk how how converting it would work tho, I’m an animator not,a game dev.

    • @aksimilumaspvp7278
      @aksimilumaspvp7278 4 года назад +3

      Nintendo is shit to deal with if i am right. It needs some extra work to get games there and putting games on pc is 100times easier. But still yeah it is possible and would be cool

    • @aspenpawarts9333
      @aspenpawarts9333 4 года назад +1

      AksimilumasPvP true true- from what I know is it’s not hard, just tedious. Otherwise how would trash and asset flips get on there?

  • @ApexArtistX
    @ApexArtistX 4 года назад

    Vector2 currentPosition =(Vector2)transform.position + (transform.right * force * t) + 0.5f * Physics2D.gravity * (t*t);
    CS0034 Operator '+' is ambiguous on operands of type 'Vector2' and 'Vector3'
    where am i going wrong ?

  • @sou_arts
    @sou_arts 4 года назад

    Awesome video as usual noa !
    I'm learning a lot from ya ♡

  • @Adam15841
    @Adam15841 2 года назад

    Anyone know how I can change the launch force according to how long you hold down the Input key?

  • @JavierMorales-qo4ok
    @JavierMorales-qo4ok 3 года назад

    I have a question ¿Which text editor do you use?

  • @atharvag581
    @atharvag581 4 года назад +1

    where to download the the source code please tell fast????

  • @a_person1226
    @a_person1226 4 года назад +1

    lol is anyone else getting the "NullReferenceException: Object reference not set to an instance of an object
    Bow.Update () (at Assets/Bow.cs:18)" when they put in the code? pls help lol

    • @BogdanSlow
      @BogdanSlow 4 года назад +1

      if you still need this after 1 month :)) . you need to have the dot in the hierarchy.

    • @a_person1226
      @a_person1226 4 года назад +1

      @@BogdanSlow lol thanks but i figured it out :))

  • @aarondelgado3421
    @aarondelgado3421 4 года назад +1

    Nice tutorial! However, it would have been easier to just use a line renderer for the points emanating from the bow.

    • @CntPnr
      @CntPnr Год назад

      I'm trying to make points work properly on my angry birds clone. Do you have any video guide suggestions that I can watch about this tip you just gave ?

  • @mehmedcavas3069
    @mehmedcavas3069 4 года назад +1

    Grear tutorial liam. However, u should show to cache most of the variables for better performans. I know this is a beginner tutorial but would be still good :) still a very good video 👍🏻💪🏻

    • @poid96
      @poid96 4 года назад

      Agreed! Especially when using camera.main, as that translates to a "FindObjectOfType()" if I recall correctly from one of the Unity Unite talks, which is really slow. Either create a reference in the script ([Serializefield] or public) and drag over the camera, OR at least in Start / Awake, call camera.main and store the reference for use in the script update. Camera.main use is mentioned in many tutorials and talks as a major performance issue so it is a good practice to get used to not using it in update / fixedupdate. Good job otherwise :)

  • @mokafi7
    @mokafi7 4 года назад +1

    TIP : On the arrow script use FixedUpdate() instead of Update() to have a smoother arrow.

  • @SM-zr1jc
    @SM-zr1jc 4 года назад

    Amazing. Really cool but very useful for my game

  • @labiscotte5687
    @labiscotte5687 4 года назад

    Thanks, useful video

  • @davidzap
    @davidzap 4 года назад

    Why does the angle returns in radians what's the use of that kind of angles?

    • @perssontm1628
      @perssontm1628 4 года назад

      One thing i've learned through out my coding journey is... Don't question code.. lol