2D Shooting in Unity (Tutorial)

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 พ.ย. 2024

ความคิดเห็น • 1.5K

  • @aoao1044
    @aoao1044 9 หลายเดือนก่อน +7

    It might be a little late to mention, but if your effect can't dissapear after it finished playing, try these steps:
    1. Go to the animation tab of your effect and add an event on frame n+1(3rd block on the right of 'Samples')
    2. Create a destroy script and add it under your effect prefab
    3. Go to the inspector of the animation event you just added, type 'Destroy' into the function column, no brackets
    And that shall do the work. My script looks like below:
    public class DestroyGameObject : MonoBehaviour
    {
    public void Destroy()
    {
    Destroy(gameObject);
    }
    }
    I got this solution from chat-GPT and it worked like magic. Hope it helps :)

    • @goldman3990
      @goldman3990 9 หลายเดือนก่อน

      Got it working thanks!

    • @arrowred8176
      @arrowred8176 2 หลายเดือนก่อน

      never too late! thankuuu

  • @glow_upacademy
    @glow_upacademy 6 ปีที่แล้ว +656

    Not gonna lie but he is better at speaking then my teachers, he inspires people to do stuff, he makes people positive by his smile dude, i just love watching him

    • @Brackeys
      @Brackeys  6 ปีที่แล้ว +120

      Thanks man, really appreciate the kind words! :D

    • @glow_upacademy
      @glow_upacademy 6 ปีที่แล้ว +39

      No man, thank you! Thank you for connecting with your viewers even tough you have 570,000 subscribers. It really shows that you're one of those rare youtubers who actually interact with their viewers which makes me feel happy and exited every time I watch your videos!

    • @Swagsy
      @Swagsy 6 ปีที่แล้ว +10

      Yeah, exactly! I became a game developer because of him! Thank you for everything!

    • @kingding9542
      @kingding9542 6 ปีที่แล้ว +5

      To be honest, he's definitely the person I'm gonna go to whenever I get started with unity. The videos seem so helpful
      A different kind of helpful, like I'd actually learn from them

    • @LINK1V4N
      @LINK1V4N 5 ปีที่แล้ว +7

      Gay

  • @dampee6
    @dampee6 4 ปีที่แล้ว +275

    If it seems like even after you edit the CharacterController2D script your FirePoint doesn't flip on the y-axis, click on your Local/Global button at the top of the editor. The FirePoint is flipping, but if you have one of those on and not the other, it will appear as if it's not. Regardless, as long as you've inserted the code as instructed, the bullet will come out of the FirePoint in the correct direction no matter if you have Local or Global selected.

  • @dynamite1779
    @dynamite1779 2 ปีที่แล้ว +37

    For those who cant get the Firing Point to flip with the sprite, copy lines 114-124 which can be seen seen at 2:47, this ties in with the lines at the bottom.

    • @binarybeanie6443
      @binarybeanie6443 2 ปีที่แล้ว +2

      OMG thanks dude. I’ve been trying to fix it in my game but this totally helps. 👍

    • @russianvideovlogguy
      @russianvideovlogguy ปีที่แล้ว

      Interesting, I could not figure this out and somehow managed to get the bullets to switch direction when the player turns but the firepoint is still fixed. So basically it's still broken, I will look into your suggestion. Thank you!!

    • @kindguy4330
      @kindguy4330 4 หลายเดือนก่อน

      Thank you very much bro

  • @christiang.9198
    @christiang.9198 5 ปีที่แล้ว +728

    10:54
    "Then we want to die"
    - Brackeys 2018

    • @jaqenhghar5794
      @jaqenhghar5794 5 ปีที่แล้ว +12

      "well then we want to..., Die"
      ftfy

    • @kianhunter7767
      @kianhunter7767 5 ปีที่แล้ว +7

      Story of my life

    • @igorthelight
      @igorthelight 5 ปีที่แล้ว +2

      And then:
      "I live... again!"

    • @johndobersworth4224
      @johndobersworth4224 5 ปีที่แล้ว +1

      @@igorthelight Then off in the distance:
      "CRUDUX CRUO!"

    • @igorthelight
      @igorthelight 5 ปีที่แล้ว +1

      @@johndobersworth4224 Right :-)

  • @JarJarBinkz68
    @JarJarBinkz68 3 ปีที่แล้ว +66

    after 20 + years of playing video games I finally understand how they are made :)

  • @sykoo
    @sykoo 6 ปีที่แล้ว +1020

    Glad to see both of the methods covered! :D I'm personally a prefab-guy, because screw performance lol

    • @SadSmileGames
      @SadSmileGames 6 ปีที่แล้ว +41

      Object Pooling my dude.

    • @ankurbanerjee6607
      @ankurbanerjee6607 6 ปีที่แล้ว +18

      really?? performance is my top priority than anything else, like MY GAWD!!

    • @ankurbanerjee6607
      @ankurbanerjee6607 6 ปีที่แล้ว +4

      yea, its the real sykoo, so what??

    • @ankurbanerjee6607
      @ankurbanerjee6607 6 ปีที่แล้ว +3

      no! friend

    • @vaskedagame880
      @vaskedagame880 6 ปีที่แล้ว +10

      Screw performance?
      Well not like you are making anything performance intensive like triple a titles.

  • @BDilloughery
    @BDilloughery 6 ปีที่แล้ว +24

    Dude, I teach an intro to game design class and these 2D videos are the perfect start to the school year. Keep it going!

  • @Aztek2401
    @Aztek2401 5 ปีที่แล้ว +19

    Your tutorials are so easy to follow, and really fun. They are really positive, and user friendly too. You have helped me so much, as a beginner game dev. Thanks Asbjorn! :)

  • @linshu6141
    @linshu6141 4 ปีที่แล้ว +57

    If u want that the bullet disappears after leaving the camera screen use:
    public class Bullet : MonoBehaviour
    {
    public float speed = 20f;
    public int damage = 20;
    public Rigidbody2D rb;
    public GameObject impactEffect;
    // Start is called before the first frame update
    void Start()
    {
    rb.velocity = transform.right * speed;
    }
    private void OnTriggerEnter2D(Collider2D hitInfo)
    {
    Enemy enemy = hitInfo.GetComponent();
    if (enemy != null)
    {
    enemy.TakeDamage(damage);
    }
    Destroy(gameObject);
    }
    void OnBecameInvisible()
    {
    enabled = false;
    Destroy(gameObject);
    }
    }
    It's important for the level design i think.

  • @Stevepegamer
    @Stevepegamer 4 ปีที่แล้ว +14

    If anyone had an issue with the animation not disappearing after it's end, the solution is to add a script to the gameobject that is animated by it (in that case, impactEffect and destroyEffect) that has a function that destroys the gameobject. Than all you've gotta do is to add an extra frame to the animation and place an animation event that will trigger the destroy function

    • @mrmiyagi5398
      @mrmiyagi5398 2 ปีที่แล้ว

      i have exactly that problem but i cant even solve it with your description :(

    • @shwk77
      @shwk77 2 ปีที่แล้ว

      @@mrmiyagi5398 yeah I added an event and still cannot add a function to it.. it just doesn't come up in the options under functions.

    • @sako4802
      @sako4802 2 ปีที่แล้ว

      @@shwk77 Hey, don't know if you were able to fix it or not, but here is what I did. Since we are instantiating a impact/hit effect prefab rather than changing the animation state, you need to attach a script to the hit/impact effect prefab and create a public function which the destroys the gameObject, this function would be called after the final frame of impact effects using the animation event.

    • @SDSFDSF631
      @SDSFDSF631 2 ปีที่แล้ว +2

      Can u create the script and paste it as a comment it would really help

    • @robinzhang8877
      @robinzhang8877 ปีที่แล้ว +1

      @@SDSFDSF631 What I did (a pretty dumb way) is created a script in the destroyEffect prefab in the Start frame like "Destroy(GameObject, 0.5f)" which makes it looks like that destroyEffect dissapeared right after it finished animation, but you can change the time to whatever you feel is right.

  • @cgillis3989
    @cgillis3989 9 หลายเดือนก่อน

    I'm seven minutes in and you're already providing a lot of clarity to my shooting script. Other tutorials works but their rather overly complicated and don't explain much- you fix both issues. Very good job :D

  • @taurdenga
    @taurdenga 6 ปีที่แล้ว +3

    For people using the Prefab approach, please do remember to utilize object pooling in order to maximize performance. I believe Brackeys has a video set up for this.

  • @andrewhouth3299
    @andrewhouth3299 3 ปีที่แล้ว +1

    You SAVED me life. I've been trying for 2 hours to figure how to get the bullet to shoot across. (Using other tutorials)
    This one nailed it step by step. Thanks!!!!

  • @andeheri
    @andeheri 4 ปีที่แล้ว +7

    I bought the masterclass; so far I´m loving it!

    • @gentleasp6589
      @gentleasp6589 2 ปีที่แล้ว

      Idk if you still use this account but did it work? Also is it still up even?

  • @emerykj1830
    @emerykj1830 4 ปีที่แล้ว +1

    For anyone trying to get their bullet to shoot forward instead of right, use forward in place of right, or if that doesnt work, use up. You 2D game might be oriented so that forward to your camera view is actually the green axis, or up.

  • @abdullahdief1491
    @abdullahdief1491 6 ปีที่แล้ว +131

    Can you make a tutorial about melee weapons
    BTW
    love you videos

    • @louislemur
      @louislemur 4 ปีที่แล้ว +2

      he has one

    • @osazuwauzebu2999
      @osazuwauzebu2999 4 ปีที่แล้ว +11

      LouisLemur he might have one now as this comment was made a year ago

  • @elijah2208
    @elijah2208 4 ปีที่แล้ว +44

    Alright if anyone is wondering how they can get their character to shoot while crouching here's how:
    1. Make another firepoint for the crouching position
    2. go into the weapon script and change it to this:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class Weapon : MonoBehaviour
    {
    public Transform firePoint;
    public GameObject bulletPrefab;
    public Transform firePointcrouch;
    // Update is called once per frame
    private void Update()
    {
    if ((Input.GetButton("Crouch") == true && Input.GetButtonDown("Fire1")))
    {
    CrouchShot();
    }
    else if (Input.GetButtonDown("Fire1"))
    {
    Shoot();
    }
    void CrouchShot()
    {
    Instantiate(bulletPrefab, firePointcrouch.position, firePointcrouch.rotation);
    }
    void Shoot()
    {
    Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
    }
    }
    }
    3. back into unity, place the crouching firepoint into the new firepoint slot on the weapon component
    That should make it so you can crouch and shoot.

    • @revan5535
      @revan5535 4 ปีที่แล้ว

      Ty bro

    • @microwave911
      @microwave911 2 ปีที่แล้ว

      actual legend

    • @beastmasterbg
      @beastmasterbg 2 ปีที่แล้ว

      this is actually genius

    • @marcusik178
      @marcusik178 2 ปีที่แล้ว +1

      or just move the firepoint with the animation of crouching

  • @ankurbanerjee6607
    @ankurbanerjee6607 6 ปีที่แล้ว +16

    Hey Asbjorn, I am really happy that you returned to the coding part as u were just showcasing stuff earlier. WooHoo!!!

    • @NHGeneral
      @NHGeneral 3 ปีที่แล้ว

      @CHUA RUI FENG Moe me too, because he's a legend

  • @lukeblaker5625
    @lukeblaker5625 4 ปีที่แล้ว +1

    I know this is an old video so I don't know if you'll see this but this helped me so much. I was at a dead end with my game and it was really disheartening. I felt like I couldn't progress if I hadn't got this part sorted and even though it's not exactly the type of shooting I wanted, I was lucky to find this and I'm glad I switched it out to shooting just along the X axis. Thank you!!

  • @miceonvenus647
    @miceonvenus647 6 ปีที่แล้ว +6

    I legit cracked up when the cameraman shot Brackeys. Great video as always, man, thank you! How about a stealth themed video?

  • @toreole2993
    @toreole2993 6 ปีที่แล้ว +815

    OH NO... The udemy ads are spreading from before the videos to INSIDE the videos.
    ABORT MISSION

    • @ZatriX_ZA
      @ZatriX_ZA 6 ปีที่แล้ว +11

      my sentiment exactly... (((

    • @owendorsey5866
      @owendorsey5866 6 ปีที่แล้ว +3

      Lol

    • @vaishnav_mallya
      @vaishnav_mallya 6 ปีที่แล้ว +63

      Coding your own games is easier than you think...you know..you should take this online unity course on Udemy.

    • @nanda_gamedev
      @nanda_gamedev 6 ปีที่แล้ว +15

      I'm already paying for a freaking game dev college I DONT WANT UDEMY STAAAHP

    • @ZatriX_ZA
      @ZatriX_ZA 6 ปีที่แล้ว +7

      loooooooooool )) and while you're at it, check out that shader development course, too ))

  • @enragekoala3868
    @enragekoala3868 6 ปีที่แล้ว +109

    hey Brackeys can you do a 2D tutorial on ledge grabbing and wall jumping?

    • @juhakeranen
      @juhakeranen 6 ปีที่แล้ว +7

      While you wait, there are some cool tutorials about this subject already! :) Here's one: th-cam.com/video/EOSjfRuh7x4/w-d-xo.html. This stuff also really helped me a lot: juhakeranen.com/dev-mistakes-pdf/

    • @rpgtogether7022
      @rpgtogether7022 6 ปีที่แล้ว +1

      I want AR tutorial..

    • @humphred4912
      @humphred4912 5 ปีที่แล้ว

      that would be pretty cool.

    • @anshayaramim898
      @anshayaramim898 2 ปีที่แล้ว

      th-cam.com/video/_UBpkdKlJzE/w-d-xo.html

    • @gachastorys5129
      @gachastorys5129 2 ปีที่แล้ว +1

      Hes gone now sadly...

  • @fyxtheinferno149
    @fyxtheinferno149 4 ปีที่แล้ว +1

    really loving these unity tutorials! it's always nice to see how to make a game from the perspective of an experienced game dev

  • @Strategic.
    @Strategic. 2 ปีที่แล้ว +5

    If you have a problem with the animation not disappearing after it's over, the solution is to add a script to the Object "DeathEffect" that has a function that destroys the gameobject after a bit of time (the time the animation takes).
    This Code worked for me :
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class DeathEffect : MonoBehaviour
    {

    void Start()
    {
    Invoke("EndEffect", 0.5f);
    }
    void EndEffect()
    {
    Destroy(gameObject);
    }
    }

    • @RhinoCringe
      @RhinoCringe ปีที่แล้ว

      I love you so much : ) thank you

    • @Strategic.
      @Strategic. ปีที่แล้ว

      @@RhinoCringe Anytime 😊

    • @papuz5854
      @papuz5854 ปีที่แล้ว

      It works!

    • @1wntv
      @1wntv ปีที่แล้ว

      It worked like a charm, thank you so much! :D

  • @Rydn
    @Rydn 5 ปีที่แล้ว

    Dude the way you approach your videos is so positive. You emit good vibes

  • @loot6
    @loot6 4 ปีที่แล้ว +15

    13:17 for the raycast based shooting.

  • @littlegreen4899
    @littlegreen4899 3 ปีที่แล้ว +1

    Tip to prevent lag (if you have large open areas or if it some how gets through a barrier)
    You can make a script that delays the bullet after a while such as
    Void start ()
    {
    Invoke(“despawn”, 20);
    }
    Public void despawn ()
    {
    Destroy(Gameobject);
    }

  • @niutah
    @niutah 5 ปีที่แล้ว +3

    I just love your tutorials. Even If I don't really need that at this moment it's so useful and helpful for further struggles. Always find what I was looking for and even more. And you do always smile and make it all interesting. Just great job, thank you :D.

  • @brandonlee0115
    @brandonlee0115 6 ปีที่แล้ว +1

    Brackeys is back at it again with the amazing 2d tutorials

  • @andrewkerr9438
    @andrewkerr9438 6 ปีที่แล้ว +37

    I just made a AR app in unity, I feel so accomplished in life!

    • @romerpagaduan3067
      @romerpagaduan3067 6 ปีที่แล้ว

      Cool!!!!

    • @MaThMaTa1000
      @MaThMaTa1000 6 ปีที่แล้ว +1

      Name of the app so we can spam 5 stars? :D

    • @andrewkerr9438
      @andrewkerr9438 6 ปีที่แล้ว

      @@MaThMaTa1000 hey thanks man, but it's just a fun little project I made, it isnt on the app store.

    • @WTRMLN-zu6ob
      @WTRMLN-zu6ob 5 ปีที่แล้ว +1

      Dj Khaled (andrew) suffering from success

  • @spiritos2216
    @spiritos2216 6 ปีที่แล้ว +1

    This is the happiest man on youtube (Machalla)

  • @MrDona5
    @MrDona5 3 ปีที่แล้ว +6

    If anyone has a problem when shoot to right or left and bullet doesn't appear try to modify the position Z = 0 on the FirePoint, it's because bullet spawns out of the camera.
    PD: Hope this solve your problem :)

  • @kazimashiatsumaira1684
    @kazimashiatsumaira1684 3 ปีที่แล้ว +2

    Amazing, all your tutorials are dope, easy to understand and simply the best unity tutorials. Please provide us with more awesome tutorials like these. Looking forward. Much love😊

  • @paz7058
    @paz7058 4 ปีที่แล้ว +75

    Who else is just trying to be like Dani

    • @fabianchelba1831
      @fabianchelba1831 4 ปีที่แล้ว +6

      Same...
      But kinda THICK

    • @paz7058
      @paz7058 4 ปีที่แล้ว +5

      X Gamer X Really THICCCCC

    • @Sparkproductions11
      @Sparkproductions11 ปีที่แล้ว

      Me

    • @Sparkproductions11
      @Sparkproductions11 ปีที่แล้ว

      But is it just me or is the gun locking kinda THICK

    • @VaneTheLocal
      @VaneTheLocal ปีที่แล้ว

      Is it me or is this comment lookin kinda THICK?

  • @oren7404
    @oren7404 6 ปีที่แล้ว

    Glad to see both of the methods covered! :D I'm personally a RayCast-guy, because Vector performance lol
    but I use ;
    Ray ray = new Ray(transform.position , transform.left);
    RaycastHit Block ;
    if(Physics.Raycast(ray , out Block , 6f))
    {
    Enemy enemy= Block.transform.GetComponent();
    if(enemy != null)
    {
    enemy.TakeDamage(10);
    }
    }

  • @Noob-nc5jq
    @Noob-nc5jq 6 ปีที่แล้ว +4

    Man, I can’t sleep without hearing your voice lol, so soothing and professional

  • @Yemto
    @Yemto 2 ปีที่แล้ว

    Thank you so much, I just started with Unity and wasn't sure how to create objects that kept the same components. Because of this video I learnt what a Prefab was, which solved my issue.

  • @albarnie1168
    @albarnie1168 6 ปีที่แล้ว +17

    Using colliders on the bulletsbis quite inefficient. It is much better to do a linecast from the bullet's last position to it's current one. This also means you can make bullets that can go through walls and find the out point.

    • @Swirlstudios
      @Swirlstudios 6 ปีที่แล้ว +2

      This method also solves the problem of collision detection not resolving a hit when the bullet is moving too fast.

    • @MrCooldude4172
      @MrCooldude4172 6 ปีที่แล้ว

      Could you elaborate please?

    • @Swirlstudios
      @Swirlstudios 6 ปีที่แล้ว +3

      On your bullet script, you have a variable that keeps track of the last position it was in. Every frame you do a linecast from the last position, to the current position. If the bullet collided with something during that last frame of movement, the linecast will pass through what the bullet hit. This solves the collision system not resolving a hit, because no matter how far the bullet travels in that one frame, the linecast will still pass through whatever the bullet hit.
      Regarding the wall part, if you want penetration, when you do the linecast, you can check if the linecast passed through a wall. If it did, you can use vector math to figure out where the bullet came out of the wall and at what angle.

    • @MrCooldude4172
      @MrCooldude4172 6 ปีที่แล้ว

      @@Swirlstudios thanks dude! Any idea whether we can do this on gamemaker?

    • @Swirlstudios
      @Swirlstudios 6 ปีที่แล้ว

      @cooldude 4172 I don't have any experience with that engine, but a quick google search brought up the collision_line method which may help you docs.yoyogames.com/source/dadiospice/002_reference/movement%20and%20collisions/collisions/collision_line.html

  • @Yoshi_green
    @Yoshi_green 6 ปีที่แล้ว +2

    19:50 if you want to wait for exactly 1 frame, then imo it's more accurate to use
    yield return Time.deltaTime
    because that's the length of the last frame. of course it's not 100% accurate because of varying frame lengths but it should be closer than 0.02 seconds

  • @linshu6141
    @linshu6141 4 ปีที่แล้ว +4

    If ur enemy doesn't disappear if it's health goes under 0 health just delete the line "Instantiate(deathEffect, transform.position, Quaternion.identity);" in the enemy script.

    • @emirkucuk7972
      @emirkucuk7972 ปีที่แล้ว

      Thank you man, saved my day!

  • @jaimealbaruiz7570
    @jaimealbaruiz7570 8 หลายเดือนก่อน

    huge thanks dude, my shooting just skyrocketed thanks to you

  • @zahhym
    @zahhym 4 ปีที่แล้ว +4

    Thank you so much, this helped me more than anything ive seen yet (not saying much since this is the second video ive watched but still Its good)

  • @psitaxx
    @psitaxx 4 ปีที่แล้ว

    For a beginner like me the salto jump at 2:08 was just a huge flex

  • @asia_crasia
    @asia_crasia 6 ปีที่แล้ว +6

    Could you go over the controller script in an upcoming video? It would be really helpful to understand what's happening in it step-by-step so when we start our own projects we don't have to rely on other people's scripts

  • @morphman86
    @morphman86 5 ปีที่แล้ว +1

    Quick tip:
    Add a float: impactEffectTime
    This is the time the impact effect animation plays, roughly. The effect should end on an invisible frame, so it doesn't show, but if you look at the inspector, the prefab is still there. After a few thousand shots, this could slow down your game. With a timer of, say, half to one second, you could destroy the effect prefab as well. By having this as a variable, you can use much longer effects, in case you have special weapons with much longer effects in the future. Like a rocket with secondary explosions.
    This will then clean up the effect prefabs for you and you shouldn't have more than maybe 10 effect prefabs at any given time, and no significant impact on performance.
    To implement, just copy the Destroy command from the bullet itself, place right before the bullet, change the variable name from the bullet game object to the effect game object and add the timer as a second parameter. It looks like it would destroy the effect prefab first, but the second parameter is actually a timer, so the bullet would be destroyed instantly, and the effect would be destroyed impactEffectTime seconds later.

  • @npmeyer77
    @npmeyer77 6 ปีที่แล้ว +15

    "Let's not jump the gun on this one" - Dad Joke level 100

  • @dharmeshkumar2763
    @dharmeshkumar2763 6 ปีที่แล้ว +1

    You are a very good teacher. You know how to explain a complicated things in a simple way. I like this tutorial 😊. Keep making such tutorials.

  • @KarlooAudi
    @KarlooAudi 6 ปีที่แล้ว +28

    Brackeys. I know this request might be pointless, but could you please, I beg you, make tutorial with shader graph related to rain ripples and rainy window drops and if you find time, character that looks like a ghost, but shaped like character :)

    • @AmantePatata
      @AmantePatata 6 ปีที่แล้ว +3

      You could make a ghost by making a character transparent, ramping up its emission + using an bloom aftereffect to blur the edges

    • @KarlooAudi
      @KarlooAudi 6 ปีที่แล้ว

      I want the ghost that looks like in call of duty black ops 4
      th-cam.com/video/h_fKrz85o8I/w-d-xo.html
      10:46 skip

  • @it1shka
    @it1shka 5 ปีที่แล้ว

    your english is so clear and understandable

  • @ashtonvaleroso
    @ashtonvaleroso 6 ปีที่แล้ว +14

    Can you do a tutorial on making particle clouds pls. I need help for making one in my game. I don’t want to use a skybox by the way.

  • @darkwyvern9796
    @darkwyvern9796 6 ปีที่แล้ว +1

    BEST shooting tutorial for 2D out there, thank you!
    I got a question tho and I really hope you'll answer, how did you turn the impact animation into a useable prefab? I'm banging my head over this and it should'nt be so hard haha

  • @kirill5437
    @kirill5437 5 ปีที่แล้ว +3

    7:19 just my bookmark

  • @TheFunkyWood
    @TheFunkyWood ปีที่แล้ว +1

    For people who want the shots to not affect the player, here is a fix:
    in the bullet rigidbody, press layer overrides, then add a new layer called player to the excludes. add the player to this layer, and the bullet will ignore it.

    • @curlyfries1013
      @curlyfries1013 หลายเดือนก่อน

      I know this is late but does this work with raycast shooting as well??

    • @TheFunkyWood
      @TheFunkyWood หลายเดือนก่อน

      @@curlyfries1013 I dont even remember making this comment, and have not used unity in months

  • @toddholford2239
    @toddholford2239 6 ปีที่แล้ว +38

    Has anyone else had an issue where your impactEffect prefab plays through it's animation and then doesn't go away?

    • @arjunakula2624
      @arjunakula2624 5 ปีที่แล้ว

      make sure the animation isn't looping

    • @billynewcomb2485
      @billynewcomb2485 5 ปีที่แล้ว +1

      I have the same problem. The animation will play and then stop, but the impact is sticking to the wall. The animation loop is off.

    • @duskmoth
      @duskmoth 5 ปีที่แล้ว +1

      I had the same problem, i downloaded an empty png then add it to end of the impact animation and enemy death animation it fixed mine but im sure there is much better solution

    • @massimogrilli6467
      @massimogrilli6467 5 ปีที่แล้ว

      Mee too. Has anyone solved it?

    • @billynewcomb2485
      @billynewcomb2485 5 ปีที่แล้ว +1

      You need to put an empty frame at the end of the animation. I also had to create a destroy object script for it to delete it from the hierarchy.

  • @ralofpatel470
    @ralofpatel470 6 ปีที่แล้ว

    Miss good old days when you used to create Intermediate to advanced series of videos. Now you have gone back to lesson 1

  • @alexflim
    @alexflim 6 ปีที่แล้ว +3

    I really hope to see "shooting as particle system" guide in some future, cause alot of prefabs hit ur frame rate pretty hard

  • @siranjivsivapalan6254
    @siranjivsivapalan6254 2 ปีที่แล้ว +2

    To people who have trouble with gunpoint flipping issue(Gun point changing direction) you can use this
    Have 2 Variables
    private bool isFacingRight = true;
    private bool isFacingLeft = false;
    Then the rest of the logic is below
    Also this is a script if you designed your player facing right
    if (movementX > 0)
    {
    anim.SetBool(WALK_ANIMATION, true);
    anim.SetBool(JUMP_ANIMATION, false);
    if (isFacingRight == true)
    {
    transform.Rotate(0f, 0f, 0f);
    isFacingRight = true;
    isFacingLeft = false;
    }
    else
    {
    transform.Rotate(0f, 180f, 0f);
    isFacingRight = true;
    isFacingLeft = false;
    }
    }
    else if (movementX < 0)//we are going to the left
    {
    anim.SetBool(WALK_ANIMATION, true);
    anim.SetBool(JUMP_ANIMATION, false);
    if (isFacingLeft == true)
    {
    transform.Rotate(0f, 0f, 0f);
    isFacingLeft = true;
    isFacingRight = false;
    }
    else
    {
    transform.Rotate(0f, 180f, 0f);
    isFacingLeft = true;
    isFacingRight = false;
    }
    }
    Note: The anim.SetBool stuff are my animation code you can ignore that but the logic should work
    Hope it helps anyone :D

  • @DayMoniakkEdits
    @DayMoniakkEdits 6 ปีที่แล้ว +6

    Don't forget to destroy the impacts effects after a few seconds because of performance issues

    • @thewiitard5515
      @thewiitard5515 6 ปีที่แล้ว

      How do you do that?

    • @DayMoniakkEdits
      @DayMoniakkEdits 6 ปีที่แล้ว

      @@thewiitard5515 Destroy (gameObject, lifetime);

    • @thewiitard5515
      @thewiitard5515 6 ปีที่แล้ว

      @@DayMoniakkEdits It says that lifetime is an error

    • @DayMoniakkEdits
      @DayMoniakkEdits 6 ปีที่แล้ว +1

      The Wiitard lol don't write "lifetime", put the amount of time in seconds, for example "3f" to destroy the bullet after 3 secs :)

    • @thewiitard5515
      @thewiitard5515 6 ปีที่แล้ว

      @@DayMoniakkEdits my problem is that the animation doesn't delete when its done it just stays at the last frame of animation

  • @vincebilotti8301
    @vincebilotti8301 2 ปีที่แล้ว

    This video has so much value, keep up the good content!!

  • @wissamalhourani2291
    @wissamalhourani2291 5 ปีที่แล้ว +17

    0:49 the second guy has aimbot !

  • @tanintygamestudio734
    @tanintygamestudio734 6 ปีที่แล้ว

    TIP:-
    1. what if i'm shooting hundreds of bullet?
    -Object pooling is best technique while handling numerous bullets
    2. Is Rigid Body really necessary?
    -Rigid body on each bullet should be avoided
    3. Should i really need to rotate Shooting point ?
    -For shooting point simply use local direction instead of vector3.right use transform.right, no need to rotate it by 0-180 deg

  • @techtutorials-i8d
    @techtutorials-i8d 5 ปีที่แล้ว +3

    Really an amazing tutorial! Love from Pakistan

  • @VlogwithKing
    @VlogwithKing 6 ปีที่แล้ว +1

    Haha the look on your face when the handgun showed up. Amazing. 😂

  • @septiawanrizky1013
    @septiawanrizky1013 6 ปีที่แล้ว +5

    Brackeys, your video is make me to learn about Unity. Please make 2D Melee Attack in Unity. Thank you.

  • @yoctometric
    @yoctometric 6 ปีที่แล้ว

    Very highly polished tutorial!

  • @thesasquatch1238
    @thesasquatch1238 3 ปีที่แล้ว +10

    Hi, If someone could help me, I am doing the prefab method but whenever I shoot the bullet just stops in front of the enemy and doesn't destroy or print Enemy(or "Frog" in my case) in the console.

    • @turtle6414
      @turtle6414 3 ปีที่แล้ว +2

      I DON'T HAVE A SOLUTION BUT IM BOOSTING THE COMMENT SO MORE PEOPLE CAN SEE IT AND MAYBE ONE OF THEM CAN HELP YOU

    • @moldy9041
      @moldy9041 3 ปีที่แล้ว

      do you have isTrigger enabled under your bullet's box collider ?

    • @noahwattel4226
      @noahwattel4226 2 ปีที่แล้ว

      Same and if I turn on isTrigger it just phases through
      Nevermind: Solution: I wrote OntriggerEnter2D instead of OnTriggerEnter2D

  • @makke2170
    @makke2170 6 ปีที่แล้ว +2

    Im so glad I found this video :D super easy to understand, and exactly what I was looking for. Thank you!

  • @guigondi7671
    @guigondi7671 6 ปีที่แล้ว +15

    @Brackeys
    Please, do a 2D tutorial on how to make melee atacks and combos.
    I'd really like to try to make a 2D Devil May Cry

    • @bigfan6936
      @bigfan6936 6 ปีที่แล้ว

      Gui G Dias yeah thats a good idea

    • @phirewind
      @phirewind 6 ปีที่แล้ว

      In your animations, attach a collider trigger and animate it to follow the weapon, then apply damage with that collider similar to how the bullet detects impacting an enemy

    • @guigondi7671
      @guigondi7671 6 ปีที่แล้ว +1

      that's a good start but how should i go about balancing the weight of my enemies and forces of each attack to allow for things like juggle combos, launchers, wall bounce, these kinds of things?

    • @Dejin1
      @Dejin1 6 ปีที่แล้ว

      Hey I saw your comment on making a 2d devil may cry i'm interested in helping if you want some help?

    • @Epicvampire800
      @Epicvampire800 5 ปีที่แล้ว

      @@guigondi7671 well you could make it that when you perform a launching attack it moves the enemy up a certain distance, and that when you when you attack an enemy they enter a stagger animation that keeps them from attacking. Each hit could move the enemy up a certain distance to keep them in the air, or each hit could freeze them in place for a split second so you can continue your combo. Then make the last hit of your combo a finisher that launches the enemy far away so that you can't do zero to death combos. Understanding basic physics equations like the kinematic equations, and work will help you precisely control the physics of the combo system to make it feel the way you want.

  • @menarian9550
    @menarian9550 3 ปีที่แล้ว

    Wow I am actually currently following a course by Panjuta so I was really surprised to see him as a sponsor here.

  • @tudormuntean3299
    @tudormuntean3299 4 ปีที่แล้ว +32

    Why is TH-cam showing me this exactly after he left ?

  • @KnaufYT
    @KnaufYT 3 ปีที่แล้ว

    Thank you you are my favourite youtuber i watch you every day

  • @santoshparihar6820
    @santoshparihar6820 6 ปีที่แล้ว +3

    Thanks bro. Just one request from me - you can leave it if you don't find it worth teaching.
    Can you make video on a game where we hit the api to send data to server and then again hit the get api to receive the data back from server... It could be a series of tutorials where first we login through social media and save our email and pswd to server and then save the details of user like coins,win%,powerups,loose% etc.
    What do you think ?

    • @Sakros
      @Sakros 6 ปีที่แล้ว

      Thumbs Up.

  • @MysticAnimations
    @MysticAnimations 6 ปีที่แล้ว

    FINALLY! I have been looking for AGES!

  • @JUPEETERREXE
    @JUPEETERREXE 4 ปีที่แล้ว +3

    Hi! Can someone help me? I've been trying to add an animation when my character is shooting but I can't find a way to make it work... Either the character stays stuck at the end of the animation or the animation straight up doesn't play ;^; I've tried animation events and pretty much everything else...

    • @alexle1484
      @alexle1484 4 ปีที่แล้ว

      for the "the character stays stuck at the end of the animation " problem, destroy the character animation when it's done and instantiate the origional object

  • @lopus312
    @lopus312 6 ปีที่แล้ว +1

    this video came out just when i needed it, thanks

  • @sillyempanada3239
    @sillyempanada3239 4 ปีที่แล้ว +6

    I have a really big problem! After I create OnTriggerEnter2D, when I play the game my bullet just shows up in front of me for a split second then disappears. I would imagine this happens because the bullet doesn't know what is an enemy or not. Can someone please tell me how I can fix this problem?

    • @sillyempanadayt5493
      @sillyempanadayt5493 4 ปีที่แล้ว +3

      Same problem here! Someone help usssss

    • @wingeddiscordant1398
      @wingeddiscordant1398 4 ปีที่แล้ว +1

      Omg I'm having this exact issue and it's making me crazy. I can get it to injure the enemy but that's it.

    • @divyamkala5243
      @divyamkala5243 4 ปีที่แล้ว +1

      disable gravity of the bullet from rigidbody and mark body type as kinematic

    • @pragyakaushik5449
      @pragyakaushik5449 4 ปีที่แล้ว +1

      Same problem

    • @simn.353
      @simn.353 4 ปีที่แล้ว +1

      same

  • @frostymug3123
    @frostymug3123 6 ปีที่แล้ว +1

    Awesome video's! Newbie to Unity really appreciate your thorough explanations.

  • @GameDevAraz
    @GameDevAraz 6 ปีที่แล้ว +13

    3 ways to do it...
    Using ray-cast but spawning a prefab to follow from birth to end of ray cast!
    Making it more realistic and good!
    And you can easily adjust speed of following or reduce or what ever lol!
    Its very effective, stable and great way to make a battlefield 4 like shooter! (Realistic) the key between the two lol

    • @DanianDL
      @DanianDL 6 ปีที่แล้ว +1

      I was really hoping he would show this method, thank you for confirming it's existence!

    • @GameDevAraz
      @GameDevAraz 6 ปีที่แล้ว

      Danian D. No problemo!
      But i havent tested it yet, i see no reason this wiuldnt work, infact the first point he said which was the one i used in my 2d game and believe me... that was messy lol...specially with my inability to understand a good approach to coding!
      But his method i believe is closer to the perfection that is real life physics!

    • @hyperindigo4924
      @hyperindigo4924 6 ปีที่แล้ว

      Lol, that’s just the same as using a prefab.
      The only difference is the mode of travel for the prefab.
      Real life physics also have bullet drop, so that method alone wouldn’t make anything more realistic.

    • @DanianDL
      @DanianDL 6 ปีที่แล้ว +2

      I think he meant more stable because the hit calculation doesn't rely on an actual prefab flying towards the target. Knowing some of the weird glitches with physics in game engines, raycast seems like the safer alternative. Also let's you do whatever you want with the now-only visual bullet prefab.

    • @GameDevAraz
      @GameDevAraz 6 ปีที่แล้ว +1

      Danian D. Yes, also you can tell your ray-cast to fall towards gravity over distance with some coding ways...
      Making it stable AND realistic.

  • @huntserston3579
    @huntserston3579 6 ปีที่แล้ว

    Man love your tutorials ever since I'm learning from ya I want to add a Easter egg of you in one of my games because you deserve one!!

  • @iamlogdog
    @iamlogdog 6 ปีที่แล้ว +13

    "Well then we want to DIE"

  • @maddened3746
    @maddened3746 3 ปีที่แล้ว

    thank GOD u corrected that character controller part, i used that 2d movement script and couldnt for the life of me figure out why my player was acting drunk af

  • @CamoB-ub9my
    @CamoB-ub9my 4 ปีที่แล้ว +7

    i ran into an issue where my bullet wasnt moving at all, i had to re-assign the rigidbody in the inspector, in case this helps anyone

    • @zacharylamar7997
      @zacharylamar7997 4 ปีที่แล้ว

      I ran into the same bug, but it didn't work. What do you mean by re-assign

    • @CamoB-ub9my
      @CamoB-ub9my 4 ปีที่แล้ว

      Zachary Lamar so if you click on it in the inspector, then drag it into the slot where it is on the script

  • @AwSomeWookie1
    @AwSomeWookie1 3 ปีที่แล้ว

    for the player sprite turning left or right and you want the GameObject FirePoint to move left or right depending on where the player is facing, instead of doing:
    //spriteRenderer.flipX = false;

    //spriteRenderer.flipX = true;
    you could do:
    transform.rotation = Quaternion.Euler(transform.rotation.x, 0, transform.rotation.z);
    transform.rotation = Quaternion.Euler(transform.rotation.x, 180, transform.rotation.z);

  • @paddy7154
    @paddy7154 4 ปีที่แล้ว +3

    Hello Guys if u have the same struggle like that the animation dont want to dissapear create the effects new and add a script in that script u will put in
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class Destroy : MonoBehaviour
    {
    void Update()
    {
    Destroy(gameObject,0.5f);
    }
    }
    and then i will dissapear quickly :) hope i had can help anyone :)

    • @LookAtEachOther
      @LookAtEachOther 4 ปีที่แล้ว

      Thank you very much!! You helped me a lot!

  • @charKT-7461
    @charKT-7461 6 ปีที่แล้ว

    For those who doesn’t know, shooting a bullet that hits something instantly without travel time is called “hitscan”.

  • @IronDizaster
    @IronDizaster 6 ปีที่แล้ว +11

    " And I will see you in the next video! "
    Okay let's just scroll down and see the next on-
    " *SCREAMS INTO MIC* : *AHGHGHGAHFHAGHGAHGA* "

  • @PriyanshuAggarwal._12
    @PriyanshuAggarwal._12 2 ปีที่แล้ว

    thanks, I have been struggling to make my player fire but this tutorial helped me a lot

  • @joechristo2
    @joechristo2 6 ปีที่แล้ว +10

    10:54 “Well then we want to die”
    Excuse me?

  • @agentg9244
    @agentg9244 4 ปีที่แล้ว +1

    This was really helpful

  • @nadainspire2238
    @nadainspire2238 5 ปีที่แล้ว +3

    wish i was here 3 years ago before i started become a salaryman.

  • @snosibsnob3930
    @snosibsnob3930 6 ปีที่แล้ว +1

    Thank you for this. You have been a great help for all of my projects.

  • @goldengamer8510
    @goldengamer8510 5 ปีที่แล้ว +5

    Great tutorial, but one personal problem I'm having is that my bullets like to be invisible. Now I understand their new to the world, but I kind of don't like it when their invisible...

    • @coachmcguirk8277
      @coachmcguirk8277 5 ปีที่แล้ว +6

      Check the bullet prefabs Sorting Layer / Order in layer, it's probably layered behind stuff.

    • @nicholascarson2554
      @nicholascarson2554 4 ปีที่แล้ว +1

      It's either too low on the sorting layers or your FirePoint is too close to your Player

  • @Charditronic
    @Charditronic 6 ปีที่แล้ว

    Well... I suppose you know that this channel is a damn work of art. I have a particular doubt. My character is pixelated, and I've put a material type "Sprite> Difuse" so that it can receive light. Before watching the video I turned my character from the scale, and there was no problem. But turning it 180º for some reason looks dark. Ideas?

  • @TheDeadlyDalek
    @TheDeadlyDalek 4 ปีที่แล้ว +4

    How do you clean up those lingering "Impact Effect" game objects? You can see them build up at: th-cam.com/video/wkKsl1Mfp5M/w-d-xo.html
    The way I handled this:
    1) Added a new script to the "ImpactEffect" game object called "AnimationComplete"
    2) Created that script with these contents:
    public class AnimationComplete : MonoBehaviour {
    public void OnAnimationComplete() {
    Destroy(this.gameObject);
    }
    }
    3) Added an event to the end of the ImpactEffect animation whicah calls the "OnAnimationComplete()" event.

    • @ranchonbread4905
      @ranchonbread4905 4 ปีที่แล้ว

      All you have to do is to do Destroy(this.gameObject, 2f) the 2, or any var acts like a delay for destroying

    • @realprakho
      @realprakho 4 ปีที่แล้ว

      Thanks

  • @MaThMaTa1000
    @MaThMaTa1000 6 ปีที่แล้ว +2

    I think it's a good idea to always destroy the instantiated object after a certain amount of time. If you don't trigger any collision you will eventually have many objects created but never deleted, right?

    • @fglobal853
      @fglobal853 ปีที่แล้ว

      yes just need to add deathzone in object script

  • @nikkytek4552
    @nikkytek4552 5 ปีที่แล้ว +6

    How do you make it wait time before next fire???(very important)

    • @Evan-ri4yd
      @Evan-ri4yd 5 ปีที่แล้ว +7

      Try using this
      public class Gun : MonoBehaviour
      {
      public Transform firePoint;
      public GameObject bulletPrefab;
      public float Cooldown1 = 0f;
      // Update is called once per frame
      void Update()
      {
      Cooldown1 -= Time.deltaTime;
      if (Input.GetButtonDown("Fire1"))
      {
      if (Cooldown1

  • @elijahandrushenko6313
    @elijahandrushenko6313 4 ปีที่แล้ว

    Found a better solution for what Brackeys talks about at 3:00
    private void Flip()
    {
    // Switch the way the player is labelled as facing.
    m_FacingRight = !m_FacingRight;
    if (m_FacingRight)
    {
    transform.localRotation = Quaternion.Euler(0, 0, 0);
    }
    else
    {
    transform.localRotation = Quaternion.Euler(0, 180, 0);
    }
    }
    Quaternion.Euler rotations are better for when you want to control the aim with your mouse, his way works fine for what he's doing but I think this is better for other projects.

  • @eddiemuff0371
    @eddiemuff0371 4 ปีที่แล้ว +4

    I have run into a problem, for both the enemy and the projectile the last frame of the deathEffect/impactEffect lingers on screen permanently. Can some one help please?

    • @bomber_g
      @bomber_g 4 ปีที่แล้ว

      same here!, did you find a solution?

    • @ozmega
      @ozmega 4 ปีที่แล้ว +3

      @@bomber_g in the video the effect never "dies" he just added an extra animation frame where it goes invisible, but they are still there.

    • @Stalkie
      @Stalkie 4 ปีที่แล้ว

      @ozmega do you know how to add empty keyframes? I can't seem to make it happen

  • @ZeroCrits
    @ZeroCrits 4 ปีที่แล้ว

    Too bad I just found out about this pretty epic channel now. But I'm very glad that he made it, thanks for the epic tutorials