2D Enemy Shooting Unity Tutorial

Поділитися
Вставка
  • Опубліковано 11 вер 2024
  • Enjoy the video, if you have any questions ask in the comments down below!
    Request a tutorial here:
    forms.gle/JLBk...
    Patreon with fully explained c# scripts:
    / blakeygames
    Main Channel: / bblakeyyy
    Join the Discord: / discord
    Play my games! :
    blakey-games.i...
    play.google.co...
    Watch me Live on twitch: / bblakeyyy
    unity tutorial,unity,tutorial,unity 2d tutorial,unity ai tutorial,unity game tutorial,unity enemy tutorial,unity enemy ai tutorial,unity enemy ai,unity 2d,unity 2d shooting,unity tutorial 2d,unity tutorial for beginners,shooting,unity shooting,unity 2d game tutorial,unity 3d tutorial,unity enemy ai 2d,enemy,unity 3d,unity 2d shooting tutorial,unity shooting tutorial,tutorials,unity beginners tutorial,shooting tutorial in unity Audio used in my videos:
    ♪ Onion (Prod. by Lukrembo)
    Link : • (no copyright music) l...
    ♪ Branch (Prod. by Lukrembo)
    Link : • (no copyright music) c...
    ♪ Biscuit (Prod. by Lukrembo)
    Link : • (no copyright music) l...
    ♪ Bread (Prod. by Lukrembo)
    Link : • (no copyright music) j...

КОМЕНТАРІ • 104

  • @ElateTugboat
    @ElateTugboat 5 місяців тому +2

    I love the explanations for each thing you add, very nice tutorial!

  • @A_Name-tl6uq
    @A_Name-tl6uq 3 місяці тому +1

    To some who's bullets also dont follow the players movements check that the rigid body in code (the variable declared as rb) is the same as your character uses. For example mine was RigidBody2D so I had to alter the code to be rb = GetComponent(); rather than rb = GetComponent();

  • @Skywalker_Jedi_Master
    @Skywalker_Jedi_Master Рік тому +1

    One of the best enemy tutorials, thanks

  • @SilasRobinson
    @SilasRobinson Рік тому +2

    Awesome! Works like a charm!! :)

  • @venomradar
    @venomradar Рік тому +3

    i have a problem where the game freezes when the player dies and said the object is not set to an instance

  • @jamesbarker1994
    @jamesbarker1994 6 місяців тому

    The rotation of the bullet has saved my ass! thank you sir thumbs uppp

  • @hipunpun
    @hipunpun 8 місяців тому +1

    Very helpful, thank you very much.

  • @CodeKokeshi
    @CodeKokeshi 9 місяців тому

    great, I managed to make a homing projectile ( a shuriken that I've animated in piskel so the tutorial about the rotation was not used because the shuriken is already spinning), but instead of the enemy, it was the player doing it, foreach and length to calculate the nearest target so I can have multiple targets

  • @its_homayoun
    @its_homayoun 9 місяців тому

    it was a good video. thanks for helping me
    If I hadn't seen this video , the way that I used to detect player at a range was triggering the player with some collider😂

  • @DinosaurFalcon
    @DinosaurFalcon Рік тому +1

    Really nice thanks so much !

  • @ephraimgaming766
    @ephraimgaming766 Рік тому

    tip if your bullet isn't shooting at the position you want it to shoot it at drag the bulletpos to the rifle (this is shown in the vid but I'm saying this in case people missed)

  • @bigbob_yt
    @bigbob_yt 4 місяці тому

    Saved my game, i subbed

  • @allaboutpaw9396
    @allaboutpaw9396 Рік тому +2

    Great Tutorial, I am happy it works... The maths are not my strong point after all :P

  • @pickard1988
    @pickard1988 Рік тому

    great tutorial, nice and simple, thank you 👌

  • @Kiiwinho
    @Kiiwinho Рік тому +2

    Thank you so much

  • @Rayoski321
    @Rayoski321 2 місяці тому

    the best tutorials

  • @humanoterra4770
    @humanoterra4770 10 місяців тому

    Thank you very much, it helped me a lot.

  • @alvinnep465
    @alvinnep465 Рік тому +1

    I got this error " Missing Reference Exception: the object of type 'GameObject' has been destroyed but you're still trying to access it" and my bullet didn't spawn.

  • @alvarowwrvl
    @alvarowwrvl Рік тому

    nice, very helpful

  • @barryeren8257
    @barryeren8257 6 місяців тому

    Hello this video is really saved me hours thank you for the tutorial. I have a one simple question, in around 9:30 you use distance for shooting the player when it was near, I used collision box 2d and works the same but I really wanted to know which one is better for performance?

  • @RockstarKaboomGaming
    @RockstarKaboomGaming 5 місяців тому

    I followed the tutorial step by step but the enemy is shooting bullets towards the foot of the player. Could someone tell me what is going wrong?

  • @firewarrior8298
    @firewarrior8298 5 місяців тому

    What should I do if I want to make the enemy only shoot forward?

  • @lolerishype
    @lolerishype Рік тому +2

    I don't know why at the start even though I am outside of its detection range, IT STILL HITS ME WITH ONE, SINGLE BULLET. Then, everything works normally.

    • @lolerishype
      @lolerishype Рік тому +2

      Fixed the problem! REMEMBER TO DELETE THAT SPRITE FROM THE HIEARCHY!

    • @simonstechhacks
      @simonstechhacks Рік тому

      @@lolerishype It said that in the video :|

  • @naruto40kiba30
    @naruto40kiba30 Рік тому

    I’m having a problem where it says “the name ‘transform’ does not exist in the current context”

  • @Quadinian
    @Quadinian Рік тому

    Thanks for this video

  • @hoaxOT
    @hoaxOT 4 місяці тому +1

    You're so quick i can't keep up imo. If your teaching beginners I would reccomend going a bit slower. I found it difficult to keep up and fully understand what you was doing

  • @nimbusz260
    @nimbusz260 Рік тому

    I have problem I did what you tell but only the rotation doesn't work for me

  • @joshuaberketa7986
    @joshuaberketa7986 7 місяців тому

    Is There a way that when you die you respawn when the bullet hits you and your health is 0??!

  • @sumittiwari9272
    @sumittiwari9272 Рік тому

    Projectile is not visible in game view and it's z value is automatically set to -19.8 while is being spawned pls help

  • @aapris1986
    @aapris1986 Рік тому

    Hallo! Great video! Where can I find the video how to create this from scratch and also download assets?

  • @dieuthuydao8110
    @dieuthuydao8110 Рік тому

    nhung em lam mai khong duoc

  • @tankycatcool63
    @tankycatcool63 Рік тому

    the little bullet doesnt go towards my player

  • @zacharyhisaoka9194
    @zacharyhisaoka9194 Рік тому +1

    Great tutorial! Though I have a question wether its possible to tag all entitys with the same tag and have them shoot eachother without the bullet going for its parent.
    Basicly, exluding its parent from finding all objects of the same tag. Or a Minecraft skeleton shooting other Minecraft skeletons. Thanks!

  • @lehmspielt
    @lehmspielt Рік тому

    Can you make a video on 2d enemy ai? Not top down like you did before

  • @alexisislas-gonzalez5991
    @alexisislas-gonzalez5991 9 місяців тому

    Advice or syntax for this with a 3D object and with coroutine.

  • @chenpead
    @chenpead Рік тому

    i have a problem that when the bullet hits my player, the healthbar doesnt lower and the bullet doesnt also get destroyed after it hits me, i wonder that the bullet even touches me?

    • @chenpead
      @chenpead Рік тому

      nvm i solved it with the help of chatgpt

  • @boo24ndb
    @boo24ndb Рік тому

    very helpfull😀

  • @polskigamer2643
    @polskigamer2643 9 місяців тому

    I have the problem with the bullet, when it collides with the player it doesnt destroy, it flies by the player

  • @Peter22055
    @Peter22055 Рік тому +1

    Do you know a simple script so the enemy will rotate towards the player?

    • @VaneTheLocal
      @VaneTheLocal Рік тому +1

      Basecaly, all you have to do is check if the player transform.x is greater or lower then the enemy transform.x.
      If the player transform .x is greater than enemy transform.x, set the enemy sprite.flipx to false, if its lower, to true.
      Hope this helps.

  • @troutki
    @troutki Рік тому

    Hi there, when my player dies the camera also goes away, how do I make the cam follow my player and not get deleted with the player?

    • @troutki
      @troutki Рік тому

      Nevermind I fixed it

    • @chenpead
      @chenpead Рік тому

      @@troutki how? i have the same problem

  • @MX1732
    @MX1732 Рік тому +1

    Does this work for top down?

  • @polskigamer2643
    @polskigamer2643 9 місяців тому

    you have misspelled the OnTriggerEnter2D. it is supposed to be onTriggerEnter2D

    • @morebblakeyyy
      @morebblakeyyy  9 місяців тому

      That’s false, it’s OnTriggerEnter2D.

    • @polskigamer2643
      @polskigamer2643 9 місяців тому

      @@morebblakeyyy I have the problem with the bullet, when it collides with the player it doesnt destroy, it flies by the player

  • @jakubkonior2923
    @jakubkonior2923 Рік тому

    Any idea why my enemy shoots at the player's feet instead of sprite's center?

    • @morebblakeyyy
      @morebblakeyyy  Рік тому

      Most likely the pivot point of your sprite is at its feet

    • @jakubkonior2923
      @jakubkonior2923 Рік тому

      @@morebblakeyyy Thanks! That was the issue :)

  • @dontmindmelol6780
    @dontmindmelol6780 Рік тому

    Can i use the script for my player so it can aim without touch controls?

  • @mmusiphoko5551
    @mmusiphoko5551 Рік тому

    hi I have a problem , my enemy's projectile doesn't damage the player

    • @chenpead
      @chenpead Рік тому

      u find a solution? i have the same problem

    • @mmusiphoko5551
      @mmusiphoko5551 Рік тому

      My enemy projectile can damage the player but the projectile goes through the player it doesn't land on the player

  • @Florian69533
    @Florian69533 5 місяців тому

    6:02

  • @Milco7
    @Milco7 Рік тому

    grx

  • @neilaszemgulys6754
    @neilaszemgulys6754 Рік тому

    Bullets dont vanish after 10 seconds. How to fix that?

    • @salaan0675
      @salaan0675 Рік тому

      pretty sure its destroy(bullet,10) the first thing in brackets is the object the second thing is the ammount of time before its destroyed

    • @VaneTheLocal
      @VaneTheLocal Рік тому +1

      U use the destroy function, example:
      Destroy(bulletGameObject, 10);
      This code has to be implemented in the bullet script

    • @neilaszemgulys6754
      @neilaszemgulys6754 Рік тому

      @@VaneTheLocal thanks

    • @VaneTheLocal
      @VaneTheLocal Рік тому

      @@neilaszemgulys6754 no worries

  • @SvoPacanaAigul
    @SvoPacanaAigul Рік тому +1

    спасибо вам огромное (из России)

  • @xus9380
    @xus9380 Рік тому

    hi i have problem with the collision can u help me

    • @davidnagy2001
      @davidnagy2001 Рік тому +1

      You mean the bullet not destroying itself after colliding with the player? If so, put a BoxCollider2D on your bullet prefab and that should solve the prob.

    • @LcyYoutube
      @LcyYoutube Рік тому

      Have you figured it out?

    • @lettuce_justice9263
      @lettuce_justice9263 Рік тому

      @@LcyUA-cam I'm also curious now

    • @LcyYoutube
      @LcyYoutube Рік тому +1

      @@lettuce_justice9263 Are you struggling? Maybe I can help

    • @lettuce_justice9263
      @lettuce_justice9263 Рік тому +1

      @@LcyUA-cam Thanks for the offer, luckily I managed to fix it 5 mins later, had a missing piece, thanks anyway!

  • @bastianalvaro4500
    @bastianalvaro4500 Рік тому

    the bullet going another way from the player

    • @VaneTheLocal
      @VaneTheLocal Рік тому

      Then set the force to the opposite number, example: if force is 10, set it to -10.

    • @VaneTheLocal
      @VaneTheLocal Рік тому

      Hope this helps

  • @elisabatista909
    @elisabatista909 8 місяців тому

    What the name of the game?

  • @MAS9Nine
    @MAS9Nine Рік тому

    Does it work for 3d?

    • @VaneTheLocal
      @VaneTheLocal Рік тому

      No, it'll not work....

    • @MAS9Nine
      @MAS9Nine Рік тому

      @@VaneTheLocal bro. I’ve already tried that out. It was 5 months ago

    • @VaneTheLocal
      @VaneTheLocal Рік тому

      I was just trying to help bro...

  • @MAS9Nine
    @MAS9Nine Рік тому +1

    I get this error
    NullReferenceException: Object reference not set to an instance of an object
    EnemyBullet.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/EnemyBullet.cs:35)

    • @T0D4S
      @T0D4S Рік тому

      Have you fix that? I’m struggling to resolve it

    • @Eastyoffutt
      @Eastyoffutt Рік тому

      Have you fixed?

    • @MAS9Nine
      @MAS9Nine Рік тому

      @@T0D4S yes

    • @MAS9Nine
      @MAS9Nine Рік тому

      @@Eastyoffutt yes

    • @7sen651
      @7sen651 Рік тому

      ​@@MAS9Nine how