2D Bullet / Projectiles in Unity / 2023

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

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

  • @shortwatch4
    @shortwatch4 4 года назад +14

    The quality of this tutorials it's amazing for your number of subscribers, keep workin on it men!

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

      @@DistortedPixelStudios you could do a short tutorial series of a genre, like 5 videos for a simple game

  • @FLStudioTutorialz
    @FLStudioTutorialz 3 года назад +5

    These 5 Minute tutorials are amazing. Thank you for that. I hope it's not over yet because the last upload is over 8 month behind. Your on point every single time. Keep it up.

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

    Wow bro... this is the first tutorial of my life that is clear, fast, efficient and even better than unity tutorial.... good job, pls continue to post video, we love it

  • @alexonian9543
    @alexonian9543 Год назад +2

    old but gold, making a turret game and this got me started

  • @aroctagames4175
    @aroctagames4175 3 года назад +12

    for those who are having the issue where it only fires one direction, I figured out that it happens because of how you turn the player. if you follow the brackeys tutorials he has a guide for a 2d character controller but in a later video he changes how it is done for this exact reason. Most everything here still works but in the charactercontroller2D you need to change how you flip the player to "transform.Rotate(0f, 180f, 0f);" without the "quotes" and back in the projectile behavior script all you need is to change it to this " transform.position += transform.right * Time.deltaTime * Speed;" again without the "quotes" what is causing the problem is with scaling the sprite to change where you are facing the fix mentioned above is to make the sprite rotate rather than scale differently. because with scaling the lauchoffset stays looking to the right and will always think you are facing that direction and fire one way, but if you rotate the player parent object (change above) the lauchoffset will rotate with it, hope that helps

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

      You do know that I show how to do this later in the video right?

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

      @@DistortedPixelStudios no I just found this video today and had the problem and then found a way to fix it. Most videos I've found dont have any sort of follow up with these problems so since I didnt see any comment about it I didnt even consider it

    • @bane5807
      @bane5807 3 года назад +8

      @@DistortedPixelStudios at the end of the video? where?

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

      Hey don’t know if you still have that movement code but I don’t understand what I was supposed to do for the first fix also when I flip my character it goes invisible

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

      @@aroctagames4175 for now I’m gonna make my game with it only shooting right

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

    i love how there is this relaxing music in a video about a really hard part of programming

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

      its pretty simple actually

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

    First off this is an absolutely great video, and I'm keeping it for later, but in case there's anyone else who had the problem where the bullet spawned but didn't move forward at all the solution is in ProjectileBehavior replace the lines 6 to 10 with;
    public RigidBody2D _rigidBody //drag your the Projectile RigidBody2D into the _rigidBody box that'll be created under the script in the Projectile prefab inspector
    void Start()
    {
    _rigidBody.velocity = transform.right * Speed
    }
    I don't know why it didn't work for me and I don't see anyone else in the comments with this problem but... you can never be too sure,
    Cheers folks!

    • @MiguelRodriguez-ff9wl
      @MiguelRodriguez-ff9wl 2 года назад

      my issue was the bullet travels faster when the player is moving, but the bullet travels slower when the player is idle, however your solution was better for me anyways so thanks for that however you want to include Time.deltaTIme somewhere in there,

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

    Hello guys, thanks for wonderful tutorial series. It's been very helpful ! Please, keep continue !!!!

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

    "wow that huge" very sadistic

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

    I have a strange issue here. When facing right, it shoots right but when facing left, the projectiles still go right and collide with the player

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

      i posted a fix here its a lot to retype out but just look at that comment if you still need help

  • @christopherdoiron4294
    @christopherdoiron4294 3 года назад +1

    Not bad. Now lets get it following the mouse for directional firing!

  • @ruscyber9765
    @ruscyber9765 3 года назад +5

    It doesn't fire when the character turned to another side. (Every line of the code is written in a correct order)

    • @tigranvardanyan5530
      @tigranvardanyan5530 3 года назад +1

      It fire but colision kill the bullet
      try 2:32 transform.position += transform.right instead of transform.position += -transform.right
      the minus makes bullet fly to character

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

      @@tigranvardanyan5530 instructions unclear, now every bullet hit me

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

      @@Draunzler Try this
      void Update()
      {
      transform.position += transform.right * Time.deltaTime * Speed;
      Destroy(gameObject,3f);
      }

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

    So i have this problem. When i jump and shoot, the projectile doesn't collide with anything. Also they dont destroy on impact.

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

      Have the same weird problem, it does work with the grenades, but with these it does not work

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

    If your bullet only moves in one direction, you're probably using localScale for flipping your player whereas in this video transform.rotate(0,180,0) is used for flipping.
    So, on your Flip method, just add at the end: LaunchOffset.transform.Rotate(0f, 180f, 0f);
    And when you instantiate your bullet, write : Instantiate(projectilePrefab, LaunchOffset.position, LaunchOffset.transform.rotation)
    All should work after that ;)

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

    2:52 When I type the word, it does not offer me an article and does not accept my article, what could be the reason for this?

  • @Huy-G-Le
    @Huy-G-Le Год назад +1

    I have this problem, where:
    1# I press the left mouse one, and three projectile spawn.
    2# The projectile stay in the same spot, they won't fly any further.
    3# The projectile only appears at one side, the right side and not the left side.
    How do I fix this? Also I'm using a different Player Movement Script, doesn't seem to raise any confliction though.

  • @MiguelRodriguez-ff9wl
    @MiguelRodriguez-ff9wl 2 года назад +1

    This worked for me however the bullet travels way faster when the player is moving and shooting at the same time and the bullet travels slower when the player shoots while standing idle. To fix that, I set the rigidbody2d body type of the projectile prefab to kinematic and now it fires much better from the players move speed but now it totally ignores my collisions detections.
    Update: Just realized there a checkbox for use kinematic/static collisions when you have kinematic body type selected, I think this body type works best for this tutorial

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

      nice update and question did you run into the issue that OnCollisionEnter2D for the projectile is not firing off?

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

    why my projectile can't get out and why my character if i cilck left mouse button doing backward

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

      It's because the projectile collide with your player . I change "transform.position += -transform.right * Time.deltaTime * Speed;" to "transform.position += transform.right * Time.deltaTime * Speed;" and it worked. But the projectile is shoot in my back ... I think the code to set sprite rotation is a bit messed up but i didn't find solution

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

    When I did the codeding the LaunchOffset and ProjecttitlePrefab is not by the others like Jump Force or Movement Speed

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

    I'm getting an error where it says the namespace ProjectileBehaviour couldn't be found. I've made sure to spell it right and everything

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

    Hey i maybye need some Help ^^ so i did everything as it is shown in the video but this if (!Mathf.Approximately(0, movement))
    transform.rotation = movement > 0 ? Quaternion.Euler(0, 180, 0) : Quaternion.indentity; wasnt there last video. When i put it in it says compile error if its out the projectile only shoots in one direction to the left and if i press d it doenst shoot to the right

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

      i have the same problem have you found any solutions?

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

      @@appleduck1497 me to :c

  • @deepsolace92
    @deepsolace92 2 года назад +2

    the projectile only moves to the left, what is wrong?

  • @16bitgamers17
    @16bitgamers17 2 года назад +1

    i am getting this error: Assets\Player.cs(6,12): error CS0246: The type or namespace name 'ProjectileBehaviour' could not be found (are you missing a using directive or an assembly reference?

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

      I have the same no idea how to fix it tho

    • @16bitgamers17
      @16bitgamers17 2 года назад +1

      @@dubbelthee8877 I changed it from ProjectileBehaviour to GameObject

    • @E-Man471
      @E-Man471 2 года назад

      @@16bitgamers17 thank you

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

    easy to follow !! thanks alot

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

    Okay so in the script, i there's no Projectile prefab and launchoffset option, i dont know why cause i follow the tutorial exactly the same. Any ideas?

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

    Really helpful tutorial, keep it up man! 👍

  • @egemen5404
    @egemen5404 3 года назад +1

    OnCollisionEnter2D not working properly. When i was type "private void OnCollisionEnter2D" it looks like as a simple method. Does anyone know the solution?

  • @ruizon6899
    @ruizon6899 3 года назад +1

    For some reason whenever i shoot on the right i cant see it in the game and scene view but when i played it in 3d whenever i shoot to the right the projectile spawns behind the camera thats why i couldnt see it so i just moved the camera back so i can see it Why does it spawn behind the camera?

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

    Can anyone help when my projectiles hit the obstacles they don't destroy. There's no problem in my programming too

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

      hey did you firgure it out???

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

      Stuck as well

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

    Im having trouble with manipulating the empty objects with my mouse, I dont know but it seems like Unity doesnt let me drag it

  • @Fwsr.
    @Fwsr. 2 года назад

    to what button is the fire button assigned? it gives an error that i havent did that yet

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

    hey been following your tutorial step by step. but after i programmed the prefabs then ran the game. the console would recognise the button click but it doesn't show the circle bullet image. do you have any idea why this could be??
    EDIT: i got it shooting, however the objects are not destroying, could anyone in the comments or yourself can bring this to attention please??

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

    Thanks man this really helped me couse i am really into it and i'm working to a game and your tutorials really helped me. I really want to ask something. Can you please make a tutorial like how to pick up items like score u now how it is in Mario you pick up a coin and it gives you that coin if you can do that it will be really helpful for 2d btw couse from all the tutorials i watched yours were the most helpful and good couse you are going straight to the thing that you are showing in the video and usually almost no RUclips does that

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

    hey i used your code and my projectile donst vanish when it hits somthing and dosnt aim where im lookign, may i get help pls

  • @SuperGamePlayOfficial
    @SuperGamePlayOfficial 3 года назад +1

    Nice but how can i add range to it

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

    Thanks for this amazing Tutorial

  • @Uncrypt
    @Uncrypt 3 года назад +1

    Can somebody paste me the ProjectileBehaviour Script im getting the same error over and over and its the simplist one i just dk how to debug it.

  • @zer0._.
    @zer0._. 4 года назад

    A huge thank you...😁😄💚💚💚💚

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

    Thank you ! I tried more than 10 examples from Google. But only your code working.

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

    Great tutorial! For some reason the projectile only moves right, regardless of which way the player is facing. Would love some pointers to this problem!

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

    I wrote my script for the enemies projectiles and it worked flawlessly, but when I copy paste it to my player's the projectile just fly right through the enemy ??
    The script for the enemies can kill my player but my player's script can't, even tho it's a copy paste from the enemies ?

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

    One question, does the projectile really need a rigid body, since you are moving it with the transform?

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

    Bro, I am making a 2d top down space shooter. There is a problem in shooting system, that is , when enemy is shooting and I shoot, then the player's bullet is colliding with enemy bullet and the player's bullet is destroyed but the enemies bullet is not destroyed. Can you tell me what to do to make the both bullets passing away without any collision.

  • @Supribo
    @Supribo 3 года назад +1

    thank you for the help but my projectiles are spawning on the back of the character and launches at him

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

      do you still need help??

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

      @@zakr2084 yes pls

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

      @@Supribo so you see the game object called launch off set move it foward and if its still shooting towards you rotate z 180

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

      @@zakr2084 ok im trying it RN

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

      @@zakr2084 didnt work at all both of them

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

    Hi, nice tutorial! I have one problem, my character is only shooting to the right side. When i try to fire to the left, the projectile won't come out. Do you know what i did wrong?

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

      i dunno i have the same error
      did you fin any solutions since?

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

    The projectiles for me fire way back and don't fire at the correct line. Please help

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

    thanks you

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

    when i try to fire the characer just moves a bit and nothing happens

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

      same

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

      Your Projectile collides with the player and gets destroyed. There are 2 ways of fixing that:
      Easy-Way: Move ur LaunchOffset
      Better-Way: in "OnCollisionEnter2D" add this:
      Character2DController charControl = collision.collider.GetComponent();
      Character2DController player = charControl;
      if (!player)
      {
      Destroy(gameObject);
      ]

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

    For some reason my projectiles don't destroy whenever they hit other colliders, they just stop moving an stay there.

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

    Что мне сделать, если влево пули летят нормально, а вправо они невидимые, но наносят урон. Все перепробовал уже

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

    How can I make a delay so that you can’t constantly click to spam them

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

    How can I get rid of the clones that go for ever?

  • @theday7110
    @theday7110 8 месяцев назад

    thank you ...

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

    on what do i shoot?

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

    can you make a vid about how to shoot on cursor? (bad english srr)

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

    my bolts keep going at a 45degree angle anyone know how to fix???!

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

    it shoots only one way, to the left, but when i look right and fire, the bullets go in the same direction..

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

    hi my bullets go fro bricks what do i do

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

    what button is suppose to be the fire button?

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

      Left Mouse Button (but it depends on your settings in Unity > Edit > Project Settings > Input Manager)

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

    the block doesnt clear the bullets for me??

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

      does the block have a Collider2D on it? if not the "bullet" will just go through it

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

    how about animated projectile

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

    i dis the movement and jump tutorial but idk what button to press to jump

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

    Ho my characters :V enjoy broz

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

    for me it shoots at the right but it wont shoot at the left aswell

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

      I figured out why if you still need help with this I posted what fixed it for me on my own comment (to much to retype)

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

    Pliss make collectible item tutorial🙏🙏

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

    "Type 'ProjectileBehaviour' already defines a member called 'Update' with the same parameter types."
    No idea what that implies...

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

    My projectiles dont get destroyed when they hit something qwq

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

    Can you please put the script? It keeps giving me errors.

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

    why it only works for 1 time?????? if i die in the game and start it again, non of your codes will work

  • @костячачба
    @костячачба 2 года назад +1

    I am this close to crying I did everything the same but it's not working at all >.

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

    Dust

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

    This is a bad tuto