Shooting with Raycasts - Unity Tutorial

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

Комментарии • 3,6 тыс.

  • @Brackeys
    @Brackeys  7 лет назад +748

    I hope you will enjoy the videos guys! I will have a tutorial on Weapon Switching coming up this sunday. Oh and sorry about the over exposed footage ;)
    I hope some of you will participate in Ludum Dare this weekend - I sure will and plan to make a video about it as always :D Good luck and remember to have fun!

    • @GameS-lu2vz
      @GameS-lu2vz 7 лет назад +3

      Im looking forward to it

    • @RitobanRoyChowdhury
      @RitobanRoyChowdhury 7 лет назад +3

      Can you do some more advanced tutorials for Unity. I would love to see some prototype versions of mainstream games (e.g. Hearthstone, not No Man's Sky, etc.).

    • @jamesrandomname1000
      @jamesrandomname1000 7 лет назад +4

      I can't set up the arenas materials and textures ;(

    • @jamesrandomname1000
      @jamesrandomname1000 7 лет назад +3

      the arena doesnt come up when i drag it in

    • @jamesrandomname1000
      @jamesrandomname1000 7 лет назад +2

      i also just fall throught the arena

  • @stormillion5002
    @stormillion5002 5 лет назад +606

    "Void die" is a powerful expression

  • @Mousesenpai
    @Mousesenpai 5 лет назад +936

    he almost covered all the main aspect of FPS games in just 13 mins without any delay. amazing 10/10. This video is so much detailed .

    • @BlazertronGames
      @BlazertronGames 5 лет назад +6

      Well he used a premade FPS script.

    • @mrpotat680
      @mrpotat680 5 лет назад +8

      @@BlazertronGames He used his premade fps pack.

    • @mathstarz1168
      @mathstarz1168 5 лет назад +4

      He even discussed the nature of life's meaning as well! Did you catch it?

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

      Engrish?

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

      Bruh your gun shoots high... does anyone have a answer to this??? I know i did it correct but its not shooting on the cross hair

  • @extremegameplays7404
    @extremegameplays7404 4 года назад +682

    everybody gangsta till the cyllinder gets a gun

  • @djninjitsuchannel7857
    @djninjitsuchannel7857 6 лет назад +1963

    "so now when we go back to unity we shouldn't see any error"
    My console: 1037 errors

    • @DavidB-rx3km
      @DavidB-rx3km 5 лет назад +53

      The problems always come from not following the tutorial from start to finish - you will always miss one variable somewhere. :) I was putting this into my own script and missed the damage and range variables, and then spent 5 minutes going back through the video for it. :(

    • @_CloudyBunny
      @_CloudyBunny 5 лет назад +58

      That's the daily life of developers. : )

    • @lonttugamer2939
      @lonttugamer2939 5 лет назад +28

      @@DavidB-rx3km or following outdated tutorials, but i don't think that's the case.

    • @meganm4350
      @meganm4350 5 лет назад +4

      lolololololololol

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

      oh

  • @HOTA200
    @HOTA200 7 лет назад +772

    this is the best channel for unity users

    • @hideyboishit
      @hideyboishit 5 лет назад

      agrreedddd

    • @ferdizhivina6362
      @ferdizhivina6362 5 лет назад +1

      don't forget Jimmy Vegas , he has a good channel too

    • @humphred4912
      @humphred4912 5 лет назад +1

      he is an incredibly good teacher.

    • @mason3872
      @mason3872 5 лет назад +2

      *CODING YOUR OWN GAMES IS EASIER THAN YOU THINK*

    • @lilpup1414
      @lilpup1414 5 лет назад

      I would like but its at 420

  • @TinyDeskEngineer
    @TinyDeskEngineer 4 года назад +910

    Ah, a medieval arena, a wooden crate, and someone with a FUTURISTIC LASER BLASTER

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

      lol

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

      lol

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

      Realistik 100

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

      @Sourav Parik oh yeah, time travel makes sense.

    • @cinemacat4108
      @cinemacat4108 4 года назад +9

      I think we should appreciate that he is teaching us with some cool assets that are for free , it is a good joke tho

  • @MuditGupta89
    @MuditGupta89 6 лет назад +48

    I like how he manages to keep the content easy for newbies to understand while moving at a breakneck speed and not wasting one second of the viewers' time. That's talent right there.

  • @levibotos2534
    @levibotos2534 4 года назад +768

    Me: its correct
    Visual Studio: its correct
    Unity: you cant enter play mode with compiler errors.

    • @cosmonut-fr
      @cosmonut-fr 4 года назад +13

      You need to attach VS code with Unity

    • @cosmonut-fr
      @cosmonut-fr 4 года назад +9

      Then it will start calculating all your errors,tnx

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

      sooooooooooooooooooooooooooooooooooooooooooooooooo true XD

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

      2020 unity is the worst unity, it will ever be

    • @cosmonut-fr
      @cosmonut-fr 4 года назад +5

      @@dynacycle never be whay

  • @ignskeletons
    @ignskeletons 4 года назад +257

    I feel like I'm getting a full college level education from your RUclips channel but without any of the student debt. Thank you sir for the amazing content you provide for Unity!

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

      Me

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

      Heyyy plz help

    • @ahmedmohamed-cd7xf
      @ahmedmohamed-cd7xf 4 года назад

      Anybody having the same problem of" 'Target'Does not contain a definitionfor'TakeDamage' and no accessible extension method'TakeDamage'accepting a first argument of type 'Target' could be found" please heelp🥲

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

      @@ahmedmohamed-cd7xf save all of your .cs files, if you dont save all of them target doesnt become public

  • @jimmyfigliomeni9385
    @jimmyfigliomeni9385 4 года назад +43

    Brackeys team, I just want to say thank you for putting together all of these tutorials. They are laid out and presented well, allowing for even a novice like me to follow! Well done and I look forward to watching more in the future!

  • @redtshirtgaming4418
    @redtshirtgaming4418 3 года назад +42

    Brackeyes: void die
    void: pls no

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

    YOU ARE THE BEST I LOVE YOUR CHANNEL THANK YOU! I would have never gotten into Unity dev without you. You have been so helpful. You turned something so complicated and made it super simple. Instead of making it look easy, you make it easy. THANK YOU.

  • @Pr3DaToR15
    @Pr3DaToR15 7 лет назад +150

    So quick. .yet very detailed. Learnt a few new things. Thanks.

    • @magnusm4
      @magnusm4 7 лет назад +1

      Going by these alone, just some few things and you have the basic controls for an fps. Now just need levels, models, sound and ai

  • @yikes1910
    @yikes1910 7 лет назад +458

    The quality of these videos are amazing, keep up the good work! 💪

    • @coolboidoesstuff9828
      @coolboidoesstuff9828 5 лет назад +4

      literally. It is default 1080p HD

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

      @@coolboidoesstuff9828 time to be wooshed away

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

      @@coolboidoesstuff9828 so your telling me that FHD is normal
      dude im waching this vid in 480?

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

      @@coolboidoesstuff9828 r/whooooooooosh after 4 years get rekt

  • @MMT--Games
    @MMT--Games 4 года назад +489

    Me: *Makes Everything Correctly.*
    Unity: *999+ Errors.*

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

      You are 2 years late

    • @MMT--Games
      @MMT--Games 4 года назад +7

      @@nerdly5759 ah shit...

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

      ;-)

    • @Nuff.x
      @Nuff.x 4 года назад +2

      @@nerdly5759 so this doesn't work anymore??

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

      It works

  • @Cyreides
    @Cyreides 7 лет назад +34

    I watched this even though it's completely irrelevant to the needs of my own Unity project (I'm making a 3D platformer) because simply put... your tutorials are so interesting and thorough and insanely professional in presentation that I can't help but watch, and I still think I ended up learning somethings that I'm sure will be useful down the road.
    I'm gonna be digging through the rest of your videos as I can! Keep up the amazing work!

    • @d-o-n-u-t
      @d-o-n-u-t 5 лет назад

      Procrastination via NOT procrastination. Stop it, Cyreides... you're scaring the kids...

    • @samgillespie68
      @samgillespie68 5 лет назад

      The Diamond Gamer ?

  • @FaissalsAnimation
    @FaissalsAnimation 4 года назад +104

    It's sad that this channel is "gone"

  • @SHAHSAMINYASAR
    @SHAHSAMINYASAR 4 года назад +119

    *_Me while watching this:_* Wow,,that's so easy.
    *_Me after coding:_* error;error;error;error

    • @Hakosin-i3z
      @Hakosin-i3z 4 года назад +1

      Yes the pain

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

      @@Hakosin-i3z Hello there

    • @Hakosin-i3z
      @Hakosin-i3z 4 года назад

      @@astickman2486 General Ken Obi

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

      @@Hakosin-i3z Ahh, nice

    • @Hakosin-i3z
      @Hakosin-i3z 4 года назад +1

      @@pythro_ General Pytro

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

    That was an awesome description of the raycast hit, was able to implement the same thing to a character kicking objects, learned the transform.name and the rayccast in one video and many more things, you're awesome Brackeys!

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

    The legend never dies...

  • @CookingWithCows
    @CookingWithCows 7 лет назад +11

    I really love your channel. It helped me a lot in programming in Unity, so thank you for what you do! I would like to see a video/mini series on how to make a simple inventory system with an inventory/bag UI, different item classes that do different things when left/right clicked while held in your hand and so on. Think minecraft/harvest moon. How to make sure your character doesn't try to drink your axe or shoot with your potion. How to "make" different item classes with different properties in an outside source like a json file (a potion doesn't need a fire rate, or does it, is fire rate the same as drinking cooldown, a crossbow doesn't need a property of how much it heals you)
    and how to import them into the game as an items list. common pitfalls and things where people get stuck when creating an inventory/item system.

  • @CapitalOBeats
    @CapitalOBeats 6 лет назад +4

    Loving the tutorials brotha, Only been game making for about a month. And your videos seem to be to only ones i watch, and dont end up with a headache and a bunch of errors lol. Keep it up

  • @nuffuru1490
    @nuffuru1490 3 года назад +13

    I would recommend adding the line "ImpactGO.transform.parent = hit.transform;" after instantiating your impacteffect because if you're working with bulletholes too this way the bulletholes will move with the object they're on instead of just staying there.

    • @jacobp.6160
      @jacobp.6160 Год назад

      needed this to use the effect for different types of effects. Thank you

  • @GrayGhost28100
    @GrayGhost28100 7 лет назад +149

    I know that this is for beginners, so maybe in another tutorial you should talk about how its better to pool objects that would other wise be created a lot so that its more efficient.

    • @Brackeys
      @Brackeys  7 лет назад +40

      That's a really good idea! Noted :)

    • @invertexyz
      @invertexyz 7 лет назад +14

      Also, to use RaycastNonAlloc so that you're not generating garbage every shot that the GC has to take care of.

    • @GoldenTab
      @GoldenTab 7 лет назад +2

      Mr Anderson Noice idea! ;)

    • @cam4722
      @cam4722 7 лет назад +9

      I would LOVE to see you do an object pooling tutorial so a newbie like me can understand it!

    • @hydraxdomin8009
      @hydraxdomin8009 6 лет назад +2

      The function "Die" should be inside the class "TakeDamage".

  • @suryanshjadhav9226
    @suryanshjadhav9226 3 года назад +140

    Brackeys: so now when we go back to unity we shouldn't see any error
    Unity: We don't do that here
    Even better:
    Brackeys: so now when we go back to unity we shouldn't see any error
    Unity: *HIPPITY HOPPITY ERRORS ARE NOW YOUR PROPERTY*

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

      ikr

    • @xegrand7548
      @xegrand7548 3 года назад +6

      Is it me,or is your comment looking kinda T H I C C ?

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

      @@xegrand7548 im a dani subscriber too!

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

      @@suryanshjadhav9226 lol Karlson is off to become the most anticipated game of 2068

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

      @@xegrand7548 so we wait 47 years...
      I thought 84
      So when karlson releases when the entire fanbase i old ill tell my grandkids to buy it lol

  • @thesenate6523
    @thesenate6523 3 года назад +10

    Brackey: just create a particle that you like
    My Brain: Error 404

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

      i had to look up another tutorial

  • @createria2
    @createria2 4 года назад +212

    since I saw everyone had +1000 errors
    here you have boys enjoy:
    -Gun.cs:
    using System;
    using System.Diagnostics;
    using UnityEngine;
    public class Gun : MonoBehaviour{
    public float damage = 10f;
    public float range = 100f;
    public float fireRate = 15f;
    public float impactForce = 30f;
    public Camera fpscamera;
    public ParticleSystem muzzleflash;
    public GameObject impactEffect;
    private float nextTimeToFire = 0f;
    // Update is called once per frame
    void Update ()
    {

    if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire)
    {
    nextTimeToFire = Time.time + 1f / fireRate;
    Shoot();
    }
    }
    void Shoot ()
    {
    muzzleflash.Play();
    RaycastHit hit;
    if (Physics.Raycast(fpscamera.transform.position, fpscamera.transform.forward, out hit, range))
    {
    UnityEngine.Debug.Log(hit.transform.name);
    Target target = hit.transform.GetComponent();
    if (target != null)
    {
    target.TakeDamage(damage);
    }
    if (hit.rigidbody != null)
    {
    hit.rigidbody.AddForce(-hit.normal * impactForce);
    }
    GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
    Destroy(impactGO, 2f);
    }
    }
    }
    ---------------------------diferent script--------------------------------
    target.cs:
    using UnityEngine;
    public class Target : MonoBehaviour
    {
    // Start is called before the first frame update
    public float health = 50f;
    public void TakeDamage (float amount)
    {
    health -= amount;
    if (health

    • @drokos8239
      @drokos8239 4 года назад +9

      hi i tried it and it still doesnt work, it said: the type or namespace name Target could not be found (are you missing a using direcetive or an assembly reference) please help

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

      @@drokos8239 Just to make sure these are the 2 scripts are you sure you didnt copy the part where I enter target.cs if you didn't could you give me the exact error

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

      in Gun.cs " Target " is showing up as an error, saying it could not be found

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

      @@cianj8798 you need to do the target.cs code for that code to work

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

      there is a error called Assets\Target.cs(22,6): error CS1513: } expected

  • @krookked5868
    @krookked5868 6 лет назад +26

    you are the special person that is making my dream job possible

  • @RIP-GG
    @RIP-GG 2 месяца назад +1

    Pullin up 7 years later to say this still works in Unity 2023. Simple, clean, and timeless solution. Brackeys is tha GOAT!

    • @CreaturesCanada
      @CreaturesCanada 2 месяца назад

      Did you manage to get the flare particle system? It’s not there for me.

    • @RIP-GG
      @RIP-GG 2 месяца назад

      @@CreaturesCanada It's in the standard assets which you have to download then import via the package manager. It's still there.

  • @realcolby
    @realcolby 5 лет назад +6

    I love how easy these tutorials are for beginner and experienced programmers.

  • @billythebuilder8724
    @billythebuilder8724 3 года назад +22

    Me: deletes start method,
    visual studio: 12467147628794 errors.
    Brackeys: deletes start method,
    visual studio: 0 errors or warnings.
    me: ok i dont get it

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

    i replayed this vid 6 times just to i can help funding , but they're arent any ads, means this tutorial is really earning nothing but it taught me a lot... i love you host

    • @urielcobo-cuisana2316
      @urielcobo-cuisana2316 3 года назад +2

      He-
      He left us 10 months ago. 😭

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

      @@urielcobo-cuisana2316 i agree , we all miss him. he was the best teacher ive seen so far.. do you know someone else like him that makes similar content for "unreal engine" ? cause im really looking for one

  • @axer1015
    @axer1015 3 года назад +17

    “And we’ll create a function... let’s call it die.”
    Me whenever I’m boutta smacc someone SO HARD into the sun.

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

      Void Die()
      {
      rb.AddForce(0,1000 * Time.deltatime, 0);
      }
      Like this?

  • @akshat7310
    @akshat7310 4 года назад +634

    whose watching this after Brackeys quit?

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

    You know Brackeys, THIS helped me a shit ton right now. Thank you!

  • @sagarwankhede.thisside
    @sagarwankhede.thisside 4 года назад +4

    This worked for me. Hope it helps someone struggling like me. PS. Great tutorial Brackey!!! Thanks!
    This code is for those looking for a Gun Controller script.
    public class MouseMovement : MonoBehaviour
    {
    float mouseSensitivity = 100f;
    float xRotation = 0f;
    public Transform gunBody;
    public Transform player;
    void Start()
    {
    Cursor.lockState = CursorLockMode.Locked;
    }
    void Update()
    {
    Rotate();
    }
    void Rotate()
    {
    float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
    float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
    Vector3 gunRotation = gunBody.transform.rotation.eulerAngles;
    Vector3 playerRotation = player.transform.rotation.eulerAngles;
    xRotation -= mouseY;
    xRotation = Mathf.Clamp(xRotation, -90f, 90f);
    gunRotation.x = xRotation;
    gunRotation.z = 0;
    playerRotation.y += mouseX;
    gunBody.rotation = Quaternion.Euler(gunRotation);
    player.rotation = Quaternion.Euler(playerRotation);
    }
    }

  • @PabTSM-OfficialChannel
    @PabTSM-OfficialChannel 4 года назад +48

    Brackeys: Now we shouldn’t see any errors.
    unity: haha errors go BOOM BOOM

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

      Same lol

    • @ahmedmohamed-cd7xf
      @ahmedmohamed-cd7xf 4 года назад +1

      Im having this error " 'Target'Does not contain a definitionfor'TakeDamage' and no accessible extension method'TakeDamage'accepting a first argument of type 'Target' could be found" please heelp🥲

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

      @@ahmedmohamed-cd7xf i also have the same error

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

      @@ahmedmohamed-cd7xf ok... I found one solution... Save your progress and than restart your project... It worked for me

    • @ahmedmohamed-cd7xf
      @ahmedmohamed-cd7xf 4 года назад

      @@sparkestic1238 wow it actually worked thank you so much❤❤

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

    By far teachers like yourself are what makes Unity shine

  • @devaliero-3d597
    @devaliero-3d597 6 лет назад +13

    Ну и строчит, как пулемет, и все по делу ! Не то что другие жуют сопли и тянут резину. Лайк! Brackeys, you are an an awesome lecturer!

    • @hierayku873
      @hierayku873 6 лет назад

      СОгласен! All right!

    • @jakeschannel5461
      @jakeschannel5461 6 лет назад +1

      Жаль, что я раньше не додумался искать уроки по Юнити у зарубежных ютюберов)

  • @alwayssoftgames6636
    @alwayssoftgames6636 2 года назад +15

    If anyone wants the raycast to shoot out of a specific point of the gun (like the muzzle) instead of out of the center of the screen, do this:
    -First, go into the fire script
    -change the "public Camera fpsCam" variable to a "public Transform muzzle" variable (you can name the Transform whatever you want, I chose "muzzle")
    -Then in the "Void Shoot" function change the "fpsCam.transform.position" to "muzzle.transform.position" and the "fpsCam.transform.forward" to "muzzle.transform.forward"
    -Now in the inspector drag and drop the muzzle of the gun into the "Muzzle" component.
    -If your gun does not have a muzzle, create an empty object that is the child of the weapon, name it "Muzzle", and position it on the tip of your gun.
    Hope this helps, it worked for me.

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

      Hey, I used your code, its not dectecting the ray when I click. This is my code (I change it slightly)
      using UnityEngine;
      public class gun : MonoBehaviour
      {
      public float damage = 10f;
      public float range = 100f;
      public Transform muzzle;
      // Update is called once per frame
      void Update()
      {
      if(Input.GetKeyDown(KeyCode.Mouse0))
      {
      Shoot();
      }
      }
      void Shoot ()
      {
      RaycastHit hit;
      if (Physics.Raycast(muzzle.transform.position, muzzle.transform.forward, out hit, range ))
      {
      Debug.Log(hit.transform.name);
      }
      }
      }

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

      Nevermind sir I fixed it myself it was a issue with the rotation thank you for the info about the muzzle heres a free compliment...
      "your cool" - me

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

      Does this still work for now?

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

      you're@@jacobscott8277

  • @Dacommenta
    @Dacommenta 7 лет назад +608

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

    • @alexisbodet9195
      @alexisbodet9195 7 лет назад +75

      this dude makes me crazy..!!

    • @kryptoniancuber6063
      @kryptoniancuber6063 7 лет назад +80

      I always get that ad
      -_-

    • @brandonbennett9530
      @brandonbennett9530 7 лет назад +27

      and as soon as i gave u a thumbs up, RUclips suggested i go add free with a subscription!.... ahhh!

    • @willia_music
      @willia_music 7 лет назад +16

      Funny enough I've been taking that Udemy course starting this year. And supplemented with Brackeys it has been a lot of help. Glad I got the course before seeing the adds or else I would have been like fuck that

    • @felixjanetzki7364
      @felixjanetzki7364 6 лет назад +4

      This is so killing me

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

    The best video I have found about how to use raycasts, very well explained, with clear information.
    Thanks for the video.

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

    As as always, *the curly brackets.* :)

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

    Brackey: "we shouldn't see any errors"
    Me: "laughs awkwardly while quietly fixing a console page full of errors"

  • @lovnishjain9287
    @lovnishjain9287 5 лет назад +61

    By combining your tutorials i will make my own game soon. :)

    • @tssper3488
      @tssper3488 4 года назад +15

      Thats exactly what im doing now, except with my own terrible models and designs :)

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

      everyone is LOL

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

      @@tssper3488 Dude, you can use Google Poly for awesome models.

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

      @@tssper3488 exactly da same

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

      Same

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

    I learned SO much from this one tutorial,
    - I learned raycasts
    - I learned more variables
    - I learned how to acces scripts from scripts (lol)
    - I learned how to make a crosshair
    and WAY more, ty for the tutorial!

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

    I spent 12 days trying to get guns working in my game and MY BOY BRACKEYS HAD A VIDEO ON IT THE WHOLE TIME

  • @Gredran
    @Gredran 4 года назад +9

    Anyone having issues with the muzzle flash:
    Follow Brackeys settings, but when I learned the BIG thing stopping me from succeeded, I realized I didn't have to, because it changes AS YOU PLAY.
    Follow exactly what he does, then parent gun model to camera(as in the start) then the particle system to the gun AND use it as the target as in 9:02.
    After this, it's not shooting right? Well with the particle system parented in this path(camera-gun-particle system) go to the system and now reset the transform(like you do when you add the ground check empty to to character).
    NOW try and it should work and any setting you change should be as you play!

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

    If anybody is having trouble figuring out why their hit effect particles wont work(probably because you havent imported the effects system and just duplicated the muzzle flash and turned it into a hit effect basically), because you duplicated it, when you shoot it makes a new object right, so when its made its being awakened essentially, and because you duplicated the muzzle flash which had play on awake disabled, it wont display a hit effect. turn that bad boy on and you will have a hit effect when you shoot something. hope this helped anyone that struggled like i did

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

    4 years later still using it. You are a beast.

  • @ICTitans
    @ICTitans 7 лет назад +65

    Would you maybe do a segment on weapon recoil?

    • @FLXKZ
      @FLXKZ 7 лет назад +49

      Weapon Recoil isn't really hard. I figured out myself. Here a little demonstration:
      First, you need a Recoil Vector:
      Vector3 Recoil; //private or public doesn't Matter
      And a max recoil amount:
      public float RecoilAmmount = 0.2f; //private or public doesn't Matter again, but I would make it public for ease of use
      Now before you cast your Ray we need to get a random Vector to change the direction the ray is firing. For that we can use Random.InsideUnitCircle which should give us a random point on a circle.
      Vector2 recoil = Random.InsideUniCircle()*RecoilAmount;
      When you now Fire your ray add the Recoil to the FPSCam.transform.forward so
      if (Physics.Raycast(FPSCam.transform.position, FPSCam.transform.forward + Recoil, out RayHit))
      Hoped this helped you and other People.
      NOTE: I'm still a beginner. This should work, but I don't know if it is the most efficient way of doing it. I will make changes to this comment if someone has a better way.

    • @chinacat1337
      @chinacat1337 7 лет назад +7

      Nice recoil script, I'm a beginner too but this gives a nice spread effect to a gun good work man

    • @XGamezOnlyX
      @XGamezOnlyX 6 лет назад +2

      FYI, that script adds spread, not recoil.

    • @vaskedagame880
      @vaskedagame880 6 лет назад

      -FLXKZ-
      Couldn't you put random between (-recoilammount , recoilammount)
      To get it on left as well?
      Am I mistaking?

    • @saltyscrimp
      @saltyscrimp 5 лет назад

      @@FLXKZ Very useful my dude

  • @not_herobrine3752
    @not_herobrine3752 4 года назад +48

    Imagine being simply able to import the FPS character in later versions of unity

    • @ArthurOliveira-zq1tw
      @ArthurOliveira-zq1tw 4 года назад +3

      It would be NICE UNITY

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

      Ok so i spent a week making my own, not the best substitute, but it will do

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

      @@ArthurOliveira-zq1tw They don't now to try reducing the ammounts of assetflips made by incompetent people, I think.

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

      Hey help me

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

      @@not_herobrine3752 Brackeys has a tutorial for an fps character, you could have used that

  • @agustinquindimil6594
    @agustinquindimil6594 5 месяцев назад

    Thank you so much Brackeys, you are really the best teacher out there man!

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

    If you use the impact effect, which creates the static mark on the object being hit and you don't want it to be destroyed, instead of using Destroy(impactGO, 2f), you can use ImpactGO.transform.parent = hit.transform to maintain the mark location on objects.

    • @ahmedmohamed-cd7xf
      @ahmedmohamed-cd7xf 4 года назад

      Anybody having the same problem of" 'Target'Does not contain a definitionfor'TakeDamage' and no accessible extension method'TakeDamage'accepting a first argument of type 'Target' could be found" please heelp🥲

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

      how could I leave a bullet hole using that?

  • @duracellbattery3625
    @duracellbattery3625 5 лет назад +5

    Thank you for helping me make a game I had no clue on what to do and after watch like 5-6 videos I’m starting to get it just wanted to thank you for everything

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

    Really Useful Tutorial, We miss you Big Brack :(

  • @irvingvi
    @irvingvi 7 лет назад +5

    Good! Thank you for the tutorials, greetings from Mexico!

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

    if you want to sprint here is some code you can add:
    in "void Update" add:
    if (Input.GetKey(KeyCode.LeftShift))
    {
    speed = runSpeed;
    }
    else
    {
    speed = 6;
    }
    and add a public float called run speed with something similar to:
    public float runSpeed = 10f;
    and boom! you now have a simple running system in your game that can easily be changed.

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

    Thank you so much! Even after 4 years, this video still saved my life!!!!!!

  • @rachelabella5044
    @rachelabella5044 4 года назад +9

    just a suggestion for the commenters: If you have a recoil animation it helps to use an animation event and make the particles go off of that

  • @Matevoz72
    @Matevoz72 5 лет назад +75

    I wish he actually taught us how to make the muzzle flash cause I cannot figure out how he did it.

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

      me too

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

      @@gelis07 Yeah, I want that too. Maybe, he already made one? Can anybody tell me?

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

      @@rgb_82 he made a video about unity's particle system

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

      @@gelis07 thanks.
      edit: in case if someone wants to watch that: ruclips.net/video/FEA1wTMJAR0/видео.html

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

      Watch Ups vid

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

    Thank You So Much, I tried a few times and it didnt work but i finally got it working and am very happy with it and building off of it Thany You SOOOO SOOOO SOOOO MUC You do not understand how much this helped THANK YOU

  • @sushantdevkota1461
    @sushantdevkota1461 4 года назад +42

    This feels sad now

  • @manofqwerty
    @manofqwerty 7 лет назад +210

    Is anyone having trouble making the muzzle flash?

    • @SQUIGLEZ
      @SQUIGLEZ 7 лет назад +5

      Michael Murphy this is really late 😂😂 but I am having trouble as well. Did you find a solution to make it work?

    • @manofqwerty
      @manofqwerty 7 лет назад +3

      SQUIGLEZ I just went through it again, make sure to pay meticulous attention to all the settings and check boxes he ticks.

    • @冠霖-l4c
      @冠霖-l4c 7 лет назад +2

      I use the firerate but my muzzleflash just appear only onetime. why?

    • @shivamkumar-eq3sl
      @shivamkumar-eq3sl 7 лет назад +5

      check if it's inside the if condition which you use to fire

    • @mlgpandagames9176
      @mlgpandagames9176 6 лет назад

      no is simple

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

    I say this to every game developer.... Brackeys is a God👌

  • @marynoble-tolla7434
    @marynoble-tolla7434 4 года назад +35

    imagine actually finishing this in like 14 minutes, took me 4 hours to get everything working right.

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

      it' a day 276.......
      276 day with no success

    • @monkeyrobotsinc.9875
      @monkeyrobotsinc.9875 4 года назад

      Try 4 months dude

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

      DId you get the error of
      The type or namespace "Target" could not be found. Are you missing a using directive or assembly reference?"
      I'm stuck with this problem. I feel like Brackeys lied a lot on his tutorials :(

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

      @@victorrus01 Did you make target a public method?

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

      @Grievous i had that problem and that fixed it

  • @pongraczadam828
    @pongraczadam828 6 лет назад +63

    using UnityEngine;
    public class gun : MonoBehaviour {
    public float damage = 10f;
    public float range = 100f;
    public Camera fpsCam;
    // Update is called once per frame
    void Update () {
    if (Input,GetButtonDown("Fire"))
    {
    Shoot();
    }
    }
    void Shoot ()
    {
    RaycastHit hit;
    if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
    {
    Debug.Log(hit.transform.name);
    }
    }
    }

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

      you sir are a god

    • @Simon-tb6tn
      @Simon-tb6tn 4 года назад +2

      Input.GetButtonDown and "Fire1" but thank you so much!!!

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

      Isn't there more

    • @Simon-tb6tn
      @Simon-tb6tn 4 года назад

      @@carlosbaltazar5941 It's later in the video. This is the more boring stuff you don't have to really write to remember. It's intuitive.

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

      You're a life saver

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

    6 years later still best tutorials

  • @jorgeanimates4443
    @jorgeanimates4443 4 года назад +25

    for those who just want the code
    using UnityEngine;
    public class gunscript : MonoBehaviour
    {
    public float damage = 10f;
    public float range = 100f;
    public float fireRate = 15f;
    public Camera fpsCam;
    public ParticleSystem muzzleFlash;
    private object hit;
    public GameObject impactEffect;
    public float impactForce = 30f;
    private float nextTimeToFire = 0f;
    // Update is called once per frame
    void Update()
    {
    if (Input.GetButton("Fire1") && Time.time >= nextTimeToFire)
    {
    nextTimeToFire = Time.time + 1f / fireRate;
    shoot();
    }
    }
    void shoot()
    {
    muzzleFlash.Play();
    RaycastHit hit;
    if (Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out hit, range))
    {
    Debug.Log(hit.transform.name);
    target target = hit.transform.GetComponent();
    if (target != null)
    {
    target.TakeDamage(damage);
    }
    if(hit.rigidbody != null)
    {
    hit.rigidbody.AddForce(-hit.normal * impactForce);
    }
    }
    GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal));
    Destroy(impactGO, 2f);
    }
    }

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

      thank you man i appreciate it

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

      thx

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

      it does not work

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

      @@Tex21622 idk man, that was the code in the video

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

      you are a time saver Thanks man W comment

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

    Muzzle Flash Issue Solution:
    The solution that I found was turning the fire rate to 10 or below, for some reason when its higher the muzzle flash doesn't show up. (Also make sure to do this in Unity and not in the code as "fireRate" is a public variable). Hope this helps.

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

    After watching and following the video I threw a salute so hard that I almost cracked my skull, thanks Brackeys.
    You are a legend.

  • @techytech26
    @techytech26 4 года назад +24

    For anone having issues with muzle flash and imapact effect i have found this asset which might be useful assetstore.unity.com/packages/vfx/particles/war-fx-5669

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

      Thx

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

      THANK YOU SO MUCH!!!!!!
      YOU SAVED MY GAME!!!!!!

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

      thx, they are cool assets too

    • @CountDown-ff5nx
      @CountDown-ff5nx 4 года назад

      thank you so much man this helps a lot

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

      Thank you so much. im so bad at using UnitysParticleSystem. but it also changed my life in a good way.

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

    Either I was watching this video with *X2* Speed or Brackeys was just going *SPEEDRUN!!!*

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

      Well just watch it at 0.5x speed so he isn't going as fast as dream🤣🤣🤣🤣🤣

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

    this is the video I visit the most... Thanks Brakeys!

  • @GameS-lu2vz
    @GameS-lu2vz 7 лет назад +4

    Thanks, man! That film was really helpfull!

    • @tobycook9039
      @tobycook9039 7 лет назад +1

      m8 this aint a film, its a youtube video XD

  • @lucafrancis5572
    @lucafrancis5572 Год назад +5

    If anyone is having the issue that I lost my mind over with the particles spawning randomly. Go to Auto Random Seed under the particle system and disable it. Then go over to the shape part and change it from a cone to a sphere and make the radius and radius thickness of the sphere something very small (like 0.0001). Hope this helps

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

    best tutorial channel ever

  • @tobias231h
    @tobias231h 7 лет назад +34

    A video about your Chrome Addons would be awesome!

  • @beany_man1573
    @beany_man1573 4 года назад +15

    I Just came from the fps movement tutorial. Following along I made the gun a child of the main camera. but when I look up or down the gun has some weird stretching. How do I fix this??

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

      Me 2 and dunno how to fix it

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

      me too

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

      anybody here know how to fix it

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

      @@starky1768 how?

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

      @@sami_Sahraoi well i did just create new script and used one script from danis tutorial ruclips.net/video/XAC8U9-dTZU/видео.html&ab_channel=DanisTutorials and than i aded a gon with a script and it worked :)

  • @1.25nuclear3
    @1.25nuclear3 4 года назад +1

    This guy is..... I really love this guy.He is awesome.

  • @Cyb11893
    @Cyb11893 5 лет назад +16

    If your mazle flash does not work then you need to rewrite the script.
    void Update ()
    {
    if (Input.GetButtonDown ("Fire1"))
    {
    mazzleFlash.Play ();
    Shoot ();
    }
    }

    • @cun1nger299
      @cun1nger299 5 лет назад +4

      M A Z Z L E F L A S H

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

      how about that default particle system in unity around 9:15 where can I find that???

  • @redtshirtgaming4418
    @redtshirtgaming4418 4 года назад +6

    Can you make a tutorial on how you made the particle system/lighting for the muzzle flash please? Love your vids! :D

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

      dude in my unity the arena only has those fire things under slying platforms and thats it can someone help me ?

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

      @@alpacino6859 what do you mean?

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

      @@redtshirtgaming4418 I mean I only have those effects underneath the platforms but not all the arena can you help me ?

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

      @@alpacino6859 I was getting the same problem. What I did was kept moving the particle emitter up until the particles were by the gun. Hope this helps! :)

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

      @@redtshirtgaming4418 thx I am testing it right now

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

    thanks brackeys! your the one who got me interested in making games!

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

    ah yes, the power of unity particle system

  • @flashgames1273
    @flashgames1273 7 лет назад +18

    Pls do also gun animations, like reloading, aiming and so on! Awesome video!

    • @RitobanRoyChowdhury
      @RitobanRoyChowdhury 7 лет назад +2

      You would have to rig and animate the gun 3d models in a program like blender instead of unity. You can look up rigging or animating a gun in blender, and i'm sure you'll get many results.

    • @salahaldin5760
      @salahaldin5760 7 лет назад +1

      He can actually animate it in unity ,but the weapon shot be separate and he could then animate it in unity ,but also i prefer using other 3D software like Blender or Maya because they have much more features and tools for animation.

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

    Great videos , glad I found this channel.
    I really do appreciate people taking the time to make content like this, regardless of motivation.
    Tip for some people who may not be completely new to programming but are new to Unity and the way things are done, may help you to watch at like .75 - .85 speed. This might keep your head from exploding while trying to follow him around the Unity interface lol

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

      Do you know why the time for fire isn't working they said Time.time is read only

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

      @@unvisibleone5367 Not sure what your code looks like but.. Sounds like maybe you have something reversed.
      Stating that it is read only sounds like maybe your mean to put something like
      myvariable *= time.deltatime.
      but instead have something like...
      time.deltatime *= myvariable.
      The first one will make myvariable some value multiplied by delta time. where as the second one tries to change deltatime which can not be done.
      With out seeing your code , thats the best guess I can give you. If you havent solved it yet, I'd be happy to help a little more but would have to see some code.

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

      @@michaelwilson8461 the code is
      nextTimeForFire = Time.time * 1f / firerate ;

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

      @@michaelwilson8461 never mind I fix it

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

      @@unvisibleone5367 good stuff

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

    A lot of his tutorials work but I can’t get this one to work

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

      How So?

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

      you might try a different version of unity, I use unity 2019.2.3, and it should work for most things he shows

  • @tt3bxitbag118
    @tt3bxitbag118 5 лет назад +5

    0:30 I Recommend you to use blender when modeling your gun

    • @tt3bxitbag118
      @tt3bxitbag118 5 лет назад +1

      @Thevenot Jacob yeah me too it need 6 gb minimum RAM and my pc is... 2gb RAM 😣😣

    • @benas763
      @benas763 5 лет назад +1

      @@tt3bxitbag118 have yout tried ZBrush its really easy to run but a little complicated

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

      I CANT 3D MODELLLL

    • @Nacho-ms2pw
      @Nacho-ms2pw 4 года назад

      @@tt3bxitbag118 i have 264 gb ram what PC you have?? lmao

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

    I been searching around for fps shooting tutorials. This video is really helpful.

  • @SAPETConstantiam
    @SAPETConstantiam 5 лет назад +10

    The code target.TakeDamege (damage); doesnt work. And I dont know why because I was doing everything like you were doing.

    • @kelmish4200
      @kelmish4200 5 лет назад +2

      Is Damage is spelled wrong its "TakeDamage" not "TakeDamege" you have an e where an a is needed

    • @SAPETConstantiam
      @SAPETConstantiam 5 лет назад +2

      @@kelmish4200 yes I know I spelled that wrong but in the code I have TakeDamage and it doesnt work

    • @tharindu207
      @tharindu207 5 лет назад +2

      @@SAPETConstantiam is your TakeDamage() public?

    • @SAPETConstantiam
      @SAPETConstantiam 5 лет назад +2

      @@tharindu207 no it turnedout that i needed more code because of my camera in unity but now its working

    • @TitusSupremus
      @TitusSupremus 5 лет назад +2

      @@SAPETConstantiam what code was this

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

    The Automatic shooting was working but the particles still only showed when I clicked the mouse button not when I hold it so please help

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

      make the particle system loop

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

      Oh I already fixed it

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

      Thanks for helping though

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

      @@Konoshi186 what was your solution?

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

    This video helped me implement fire rate in my FPS game, thanks brackeys! :D

  • @ishanchoudhary4179
    @ishanchoudhary4179 4 года назад +9

    Now I know what whole unity is based on
    public float

  • @kelpdock8913
    @kelpdock8913 3 года назад +9

    lmao used this to simulate planting seeds

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

      u
      wanted to plant seeds in a game, and searched for a tutorial on how to make a gun work in unity........creative

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

      @@billythebuilder8724 yeah it was mainly for the raycasting code but it worked pretty well, got rid of the health and killing stuff and instead of instantiating a particle system it instantiates seeds which grow
      i abandoned this project tho

  • @Phoenix-0455
    @Phoenix-0455 4 года назад +1

    holy brightness

  • @robinadi7888
    @robinadi7888 3 года назад +3

    Hmmmm for the target script im getting a error
    Assets/Gun.cs(24,13): error CS0246: The type or namespace name 'Target' could not be found (are you missing a using directive or an assembly reference?)

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

      i got same issue

    • @SciencewithIrfan
      @SciencewithIrfan 10 месяцев назад +1

      @robinadi7888 @janpaweii3115 If you don't create the script (or class) called 'Target', you would get the error. So make sure to create the 'Target' class or script.

  • @DrevvDman
    @DrevvDman 5 лет назад +7

    can you make a recoil effect vid plz

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

      Its called an animation

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

      @@cr1ms0n10 Thanks for replying although I finally figured it out on my own using animations.

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

    Thank you so much for this tutorial! Really helped out a tone with my new game.

  • @jeil829
    @jeil829 4 года назад +6

    I need help turning flare to bullet impact I can’t seem to make it work