How To Make a Modular Weapon System in Unity!

  Рет қаралды 30,605

Affax

Affax

Күн бұрын

📦 Project files:
bit.ly/unitywea...
Low poly fps pack (sample): assetstore.uni...
Player Controller: gitlab.com/aff...
1:05 - Part 1 (Setup)
2:35 - Part 2 (Adding weapons)
6:25 - Part 3 (Picking up and throwing)
34:00 - Part 4 (Shooting)
43:27 - Part 5 (Ui)
50:08 - Part 6 (Extras)
Hi, my name is Affax and I'm from Finland!
I'm an independent game developer who loves to code!
In this video, I will be showing you how to make a weapon system in Unity that is modular, configurable and easy to use.
This is a longer video, but the concept shouldn't be that hard!
I hope you like this style of tutorials, where I try to explain as much as possible.
💬 Join my Discord: discord.affax....
🌐 My website: affax.dev/
🎵 Outro song (13ounce - Okay): • OKAY - 13ounce (No Cop...
Like and Subscribe!
Remember to comment your suggestions!
See you next time! :D

Пікірлер: 200
@Affax
@Affax 4 жыл бұрын
Did you learn anything new while watching this video?
@darkliongames1845
@darkliongames1845 4 жыл бұрын
i'm watching it now, really excited.. :3
@ExDee419
@ExDee419 4 жыл бұрын
my bruh i dont know anything about coding and stuff this is wasted on me e
@nicopus69dertgyhujikolp90
@nicopus69dertgyhujikolp90 4 жыл бұрын
yes u got a new sub
@Parsafari
@Parsafari 4 жыл бұрын
no
@louismastbooms5048
@louismastbooms5048 4 жыл бұрын
Could you send me the source code?
@marloweghost5097
@marloweghost5097 4 жыл бұрын
10:50 *"who even understands quaternions"* You made my last 7 minutes of my day and the next day too ;)
@Affax
@Affax 4 жыл бұрын
Thanks :D
@balucha12345
@balucha12345 4 жыл бұрын
I followed another tutorial that went over making a gun, but i got demotivated because it wasn't modular. I'm saving this tutorial for later!
@adankhan1103
@adankhan1103 4 жыл бұрын
This Man said tht he is on 200 subs and the very next 2 weeks he got 300, U deserve more affax.
@Affax
@Affax 4 жыл бұрын
Thanks!
@adankhan1103
@adankhan1103 4 жыл бұрын
@@Affax Affax i think u know me lol, from dani's server.
@marloweghost5097
@marloweghost5097 4 жыл бұрын
!!CAUTION!! For everyone using Universal Render Pipeline in Unity 2019.3: To prevent clipping, make a copy of the main camera, then remove weapon holder from new camera, change new camera's render type to Overlay, then make sure you have clear depth is on and culling mask set to Weapon Gfx. After that, find 'stack' in the inspector of the main camera and add your overlay camera to it.
@bluepixeldev
@bluepixeldev 3 жыл бұрын
If you are using Hdrp render pipeline, where camera stacking is not supported, you can add custom render pass and set specific layers to be always rendered on top.
@adityasutar7009
@adityasutar7009 3 жыл бұрын
tysm this really helped
@brandonlilly5738
@brandonlilly5738 4 жыл бұрын
This is so in depth! I love how you explain the code after you write it. It helps a lot!
@nkusters
@nkusters 4 жыл бұрын
Just finished it; nice video! I think anyone can follow this, nice job!
@Affax
@Affax 4 жыл бұрын
That's good to hear, thanks!
@jdonaldsontcs
@jdonaldsontcs 4 жыл бұрын
PLEASE keep this going bro, great video!
@desawwww
@desawwww 4 жыл бұрын
You deverse more subscribers. Your Tutorials are so helpful. Keep making them.
@Affax
@Affax 4 жыл бұрын
Thanks!
@zr0-gaming166
@zr0-gaming166 4 жыл бұрын
This is great man good job congrats on 210 subs!
@Affax
@Affax 4 жыл бұрын
Thanks!
@onerimeuse
@onerimeuse Жыл бұрын
There's so much here! What an awesome level of depth that can be accomplished in an hour of time. very cool! Definitely coming back for the grappling hook tutorial, since both of these are relevant to a game I'm working on. Thank you!
@robertkurwica
@robertkurwica 4 жыл бұрын
Wow, cool tutorial! I was just searching for that kind of stuff for my bullet hell game!
@Affax
@Affax 4 жыл бұрын
Thanks!
@lavinax
@lavinax 4 жыл бұрын
ok im gonna edit this when i finish the video, i have been looking for a gun code for weeks now i hope this is going to answer my prayers....... see you in one hour! (if i finish lmao)
@SSSPrince
@SSSPrince 3 жыл бұрын
Man's last words and he was never seen again
@lavinax
@lavinax 3 жыл бұрын
@@SSSPrince i forgot to do it, it worked
@ShadowOcto
@ShadowOcto 4 жыл бұрын
This Man Is A Legend
@Affax
@Affax 4 жыл бұрын
Thanks!
@tanh8285
@tanh8285 4 жыл бұрын
Man! I learn so much from you. Thank you!!! Great content!!!
@322ss
@322ss 4 жыл бұрын
Thanks! Interesting video. I've already created simple fps system, but it is interesting to see how you tackled things - BTW; for weaponLayer, you could use LayerMask field instead of using ints - that way you get enum/layer names dropdown for your collision mask in inspector.
@Affax
@Affax 4 жыл бұрын
I usually use LayerMask for stuff that needs multiple layers, and int for single ones. Also, not every function supports LayerMasks, so it isn't even an option always. But thanks for the feedback!
@ege924
@ege924 4 жыл бұрын
You are awsome. Keep it up.
@Affax
@Affax 4 жыл бұрын
Thanks mate!
@nkusters
@nkusters 4 жыл бұрын
Small tip: next time, try setting your editor fontsize to 150% and make your windows area smaller; works better for doing this type of video, makes sure people can read along better on smaller monitors (when YT picks 1080p; text isn't very readable; even at 1440p it could be better here for me, and I have a 3440x1440 screen; only when watching fullscreen is it nice to read)
@Affax
@Affax 4 жыл бұрын
I already put the font size 150%, but maybe I should've made it more and I made sure you can read stuff at 1080p. Resizing the monitor would have been a great idea. Also, this is my last tutorial so I can't sadly improve on that point. But thanks for feedback.
@nkusters
@nkusters 4 жыл бұрын
Affax np, trying to help. Usually people that would watch this, would have unity open at the same time to follow along, so available screen space might be very limited in scenarios like this. The premise looks interesting though, so I’ll have the video on while working, giving you some extra watch time ;)
@Affax
@Affax 4 жыл бұрын
@@nkusters I appreciate the help, and I'm really grateful that you watched my video. I will try to make more general gamedev content, because it was super exhausting to redo some of the parts of the tutorial. I also feel like these tutorials are boring, and my energy doesn't fit to them. But I feel like my other content had more entertainment value and I like to make some small prototypes in weeks and show them off. I also don't want to use old tech for tutorials, but I want to experiment and try new stuff. Also I can make better "jokes" when making casual gamedev content.
@SystembolagetOfficial
@SystembolagetOfficial 3 жыл бұрын
Doubt i will get an answer here, but i at around 28:40 right after he is done with the manager script, and i jump back into unity, i get a error message stating "There is no argument given that corresponds to the required formal parameter 'playerCamera' of 'Weapon.Pickup(Transform, Transform, TMP_Text)'" i cant find the problem in my code. Its exactly the same as his.
@daboxguy3848
@daboxguy3848 3 жыл бұрын
Are you Finnish? Also I love your box assets :)
@Affax
@Affax 3 жыл бұрын
Yes, I am Finnish haha
@Fralleee
@Fralleee 4 жыл бұрын
Very nice video. I like the format.
@Affax
@Affax 4 жыл бұрын
Thanks!
@marcamooo
@marcamooo 2 жыл бұрын
under rated
@sincerelydhruv
@sincerelydhruv 4 жыл бұрын
Thank you! I was searching for something like this. BTW, I managed to make a grappling hook by myself using spring joint. It's working really great. Only problem is that I am getting input in update and applying physics based movement in fixed update. So the movement is a bit jittery. Do you have a solution for that.
@Affax
@Affax 4 жыл бұрын
If you are using the new Input System, you can change the update time (Update or FixedUpdate). And good that you got the grappling hook working!
@Chadderbox
@Chadderbox 4 жыл бұрын
If you use LateUpdate for somethings, it may be smoother.
@RGBA
@RGBA 2 жыл бұрын
i love this tutorial, thanks for helping
@SpiceMicey
@SpiceMicey 2 жыл бұрын
I have completed the tutorial, but when i throw my weapon i can't pick it up again.
@recording_closet9100
@recording_closet9100 4 жыл бұрын
Thank you!
@hoodini_gamer8769
@hoodini_gamer8769 4 жыл бұрын
i found an error in the weapon manager that says Feature 'desclaration expresion' cannot be used because it is not part of the C# 4.0 language specification can someone help
@Affax
@Affax 4 жыл бұрын
If you follow the tutorial step by step this shouldn't happen. You probably mistyped something.
@hoodini_gamer8769
@hoodini_gamer8769 4 жыл бұрын
@@Affax i watch it again and i even copy your script from the project files but i still get an error
@Cassu.222
@Cassu.222 2 жыл бұрын
super cool
@kushalbaid
@kushalbaid 4 жыл бұрын
Nice
@Affax
@Affax 4 жыл бұрын
Thanks!
@BananaGamerB
@BananaGamerB 9 ай бұрын
I need some help sadly, when the gun reloads it turns in the Z Axis, Instead Of The Y, And i dont know how to fix it
@PedroLarock
@PedroLarock 4 жыл бұрын
00:37 say no more my man, my like and subscribe
@jugger6228
@jugger6228 4 жыл бұрын
3:17 you just solved a problem that I can´t solved for weaks xD
@PagusTheAlpagus
@PagusTheAlpagus 3 жыл бұрын
EDIT: I just figured it out by writing the lines and doing some trial and error. It's just using a lerp as an animation for the pickup function. Thanks a lot for making this video. It's very usefull. I watched the video all the way to the kickback feature but it seems that at 50:16 there is a chunk of code (between line 49 and 53 of your weapon script) magically appearing in the script. I went back to be sure I did not miss something but I didn't. or did I ??!!! I'm just confused because I don't know if it's really important or no.
@Affax
@Affax 3 жыл бұрын
Thanks for watching! I think the error came from me, as I lost a good chunk of this tutorial to something (can't remember), and had to rewrite and splice it again, and probably forgot some part from the actual video, sorry about that.
@PagusTheAlpagus
@PagusTheAlpagus 3 жыл бұрын
​@@Affax no problem! even if you forgot one part of the video, it's still an awesome tutorial and easy to follow!
@ZingyMitten8875
@ZingyMitten8875 Жыл бұрын
I’m stuck at that part. How do you implement it?
@clout8675
@clout8675 Жыл бұрын
im getting an error saying "The type or namespace name 'List' could not be found" when defining the realList, is it something on my end or did i write something wrong
@sirsatan6498
@sirsatan6498 10 ай бұрын
I can't seem to get it to work even when i copy paste everything from the project, maybe it is just that old now
@ps5games821
@ps5games821 4 жыл бұрын
Great videos Make more tutorials please
@Cdceddrcrfrftftft
@Cdceddrcrfrftftft 4 жыл бұрын
You desired 100k subs
@michaeldiamantopoulos6240
@michaeldiamantopoulos6240 Жыл бұрын
hey @Affax I'm have a Bug where when I scope there is a force pushing the player forward and I double checked the code with the one in the description plz help
@lavinax
@lavinax 4 жыл бұрын
AAAAA I CANT PICK THE WEAPON UP ITS DRIVING ME CRAZY
@alexmaster3591
@alexmaster3591 4 жыл бұрын
Thanks for this tutorial , you really helped me !! Like and big Subscribe
@Affax
@Affax 4 жыл бұрын
Thanks!
@alexmaster3591
@alexmaster3591 4 жыл бұрын
@@Affax if you can and want to make a tutorial how to create a cod scope for snipers / guns pls?
@Devsycoder
@Devsycoder Жыл бұрын
Is there anyway I could instantiate a bullet from the muzzle? Like a bullet or a trail renderer? Please and thanks 🙏
@flack..
@flack.. 2 жыл бұрын
hey @affax, great video! i had one small problem, when I have multiple guns I can make the weaponHolder position to where i want it with THAT gun, any other gun when i pick it up it goes to some random position. Do you know how to fix this problem or am i missing something? Thanks man!
@Ybot76
@Ybot76 4 жыл бұрын
380 Good job!
@idkuan
@idkuan 4 жыл бұрын
U legend for my thx
@clips_from_everything
@clips_from_everything 2 жыл бұрын
can you tell me the settings you use for the player controller because whatever I do I am sliding
@zr0-gaming166
@zr0-gaming166 4 жыл бұрын
yo can you help me how do I do this part 31:17 in the Universal Render Pipeline I can't find the clear flags part
@Affax
@Affax 4 жыл бұрын
So universal render pipeline doesn't have clear flags anymore, but you should search for another tutorial for that. I personally use Universal, but I wanted this tutorial to be accessible by almost everyone (and a lot of people still use the old tech). I can't explain it in the comments, because it is pretty hard.
@zr0-gaming166
@zr0-gaming166 4 жыл бұрын
@@Affax ok thanks
@AZASeraph
@AZASeraph 2 жыл бұрын
When I aim with the rifle and the pistol it changes the fov but it doesn't move it in front of the camera, also how could I make it so that if you have a sniper and aim it scopes it?
@catzrcool3308
@catzrcool3308 4 жыл бұрын
This is a great tutorial but for some reason when I use a capsule cast for the pickup system it has infinite range and the raycast check also doesn't work. Could someone help tell me why this is happening?
@superkakan9901
@superkakan9901 4 жыл бұрын
yo, any chance that you might make an aim down sights tutorial for this system?
@mr.jgentleman5550
@mr.jgentleman5550 4 жыл бұрын
When I try to pick up an object it says Object reference not set to an instance of an object Help
@AZASeraph
@AZASeraph 2 жыл бұрын
10:50 "Who understands quaternions" Me: pretty sure the guy invented them didn't even know what tf they were
@JustJeremyisjust
@JustJeremyisjust 4 жыл бұрын
I have a problem. When I shoot my player goes forward instead of standing still. Also I'm using Dani's Player Movement script. How do I fix that? Can you make a tutorial that will make the weapons do damage because they can't (pls).
@12Acorns
@12Acorns 3 жыл бұрын
I guess you’d have to apply a equal force back to negate the force pushing you back.
@AZASeraph
@AZASeraph 2 жыл бұрын
Is there a way to edit this to make it so the player can only have for example 2 guns at a time and if they have 2 and hit the pickup button it drops the current and picks it up, like in titanfall
@crestgamer1954
@crestgamer1954 4 жыл бұрын
Hey just subscribed.. I enjoy your videos a lot Can you make a turorial on 2d grappling hook plzz
@Affax
@Affax 4 жыл бұрын
This is probably my last tutorial, sorry.
@crestgamer1954
@crestgamer1954 4 жыл бұрын
But,why???
@Affax
@Affax 4 жыл бұрын
@@crestgamer1954 I feel that tutorials are boring, and I only can do 3d games
@yeeped2363
@yeeped2363 Жыл бұрын
Is there a way to add weapon switching? I spelt it wrong first lol
@АлиМохсин-ц2ь
@АлиМохсин-ц2ь 4 жыл бұрын
Thank u very much,,,
@ruandelange1960
@ruandelange1960 4 жыл бұрын
Sub 210 this is really well done
@Affax
@Affax 4 жыл бұрын
Thanks!
@Danboodles
@Danboodles 3 жыл бұрын
Hey, so I have written all the code up till 26:44 and the error is in the line: var realList = new List(); line 32 for me this is the error: Assets\Scripts\Shooting Scripts\WeaponManager.cs(32,32): error CS0246: The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?)
@Danboodles
@Danboodles 3 жыл бұрын
I found a comment with the same error and I feixed it, thanks still!
@AZ13_
@AZ13_ 2 жыл бұрын
if you have the same problem make sure you have these lines of code at the top using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI;
@wilder-mo
@wilder-mo 3 жыл бұрын
Hey I have a Problem. it says " The type or namespace'List' could not be found " I did everything just like you did, but its not working! Can somrone help me pls?
@Affax
@Affax 3 жыл бұрын
Well, you didn't import that file, adding this to the top should work: using System.Collections.Generic;
@wilder-mo
@wilder-mo 3 жыл бұрын
@@Affax Wow you just got to be my favorite unity Tutorial KZbinr. Thanks for the Fast Response.
@etusuku763
@etusuku763 4 жыл бұрын
Miten affax oppi koodaamaa? oisko sul jotai vinkkejä?
@Affax
@Affax 4 жыл бұрын
Minun mielestä paras tapa oppia koodaamaan on katsomalla videoita ja tekemällä aluksi pieniä projekteja. Itse opin vaan kokeilemalla ja tekemällä.
@potatoman5878
@potatoman5878 4 жыл бұрын
At 41:30,what you mean by opening weapon scrip?
@yeeped2363
@yeeped2363 Жыл бұрын
Is there a way to add weapon swito
@xx-nilsdrev-xx9585
@xx-nilsdrev-xx9585 4 жыл бұрын
Hello I found out that there is a problem with the pickup because when you r carrying a weapon you still able to pickup a another weapon which we should not. So if someone know how to fix this my ears are opened. I’m also looking if someone know how to make recoil and bloom thx. Btw the video was so helpful
@Affax
@Affax 4 жыл бұрын
If you follow the tutorial 1 by 1 (you can check the source in the description) it disallows picking up multiple weapons. Recoil is surprisingly hard to make (and I personally haven't even perfected it after multiple systems...) But I hope you can fix the pickup problem!
@xx-nilsdrev-xx9585
@xx-nilsdrev-xx9585 4 жыл бұрын
@@Affax thanks
@xx-nilsdrev-xx9585
@xx-nilsdrev-xx9585 4 жыл бұрын
@@Affax do you know how to make a taking dommage systeme who will work with the system in the video ? thanks
@Danboodles
@Danboodles 3 жыл бұрын
I just finished until 28:43 but when I press E it doesn't work, any idea as to why? Here is my script btw: using System.Collections.Generic; using UnityEngine; public class WeaponManager : MonoBehaviour { public float pickupRange; public float pickupRadius; public int weaponLayer; public Transform weaponHolder; public Transform playerCamera; private bool _isWeaponHeld; private Weapon _heldWeapon; private void Update() { if (_isWeaponHeld) { if (Input.GetKeyDown(KeyCode.Q)) { _heldWeapon.Drop(playerCamera); _heldWeapon = null; _isWeaponHeld = false; } } else if (Input.GetKeyDown(KeyCode.E)) { var hitList = new RaycastHit[256]; var hitNumber = Physics.CapsuleCastNonAlloc(playerCamera.position, playerCamera.position + playerCamera.forward * pickupRange, pickupRadius, playerCamera.forward, hitList); var realList = new List(); for (var i = 0; i < hitNumber; i++) { var hit = hitList[i]; if (hit.transform.gameObject.layer != weaponLayer) continue; if (hit.point == Vector3.zero) { realList.Add(hit); } else if (Physics.Raycast(playerCamera.position, hit.point - playerCamera.position, out var hitInfo, hit.distance + 0.1f) && hitInfo.transform == hit.transform) { realList.Add(hit); } } if (realList.Count == 0) return; realList.Sort((hit1, hit2) => { var dist1 = GetDistanceTo(hit1); var dist2 = GetDistanceTo(hit2); return Mathf.Abs(dist1 - dist2) < 0.001f ? 0 : dist1 < dist2 ? -1 : 1; }); _isWeaponHeld = true; _heldWeapon = realList[0].transform.GetComponent(); _heldWeapon.Pickup(weaponHolder); } } private float GetDistanceTo(RaycastHit hit) { return Vector3.Distance(playerCamera.position, hit.point == Vector3.zero ? hit.transform.position : hit.point); } }
@Affax
@Affax 3 жыл бұрын
Hmm, you should compare the code with the code from the description and see what mismatched. If the code is identical, then something's up with setup (you may have forgotten to apply the Weapon layer)
@Danboodles
@Danboodles 3 жыл бұрын
@@Affax I will do it again and if it is not I'll check the setup
@Danboodles
@Danboodles 3 жыл бұрын
@@Affax I have fixed it and can now pick it up, but I am unable to drop it when I press Q, the script is the exact same.
@343guiltyspification
@343guiltyspification 8 ай бұрын
@@Danboodles What did you do to fix the pick-up? (I am having the same issue...)
@Danboodles
@Danboodles 3 жыл бұрын
So I am having quite a few visual errors in the setup when I tried to add the part so the weapon doesn't have errors, I followed the tutorial precisely but it either still clips, or it does, but it keep changing, I have no idea what is causing this.
@Danboodles
@Danboodles 3 жыл бұрын
And when I did this whenever I dropped the weapons I was unable to add them back on...
@Affax
@Affax 3 жыл бұрын
At this point I hsv no clue what could be broken (quite vague) so I'd recommend looking at the source I left in the description and comparing your scripts, there's a lot you could've missed as the tutorial is an hour long (easy to make one fatal error).
@nybro9437
@nybro9437 4 жыл бұрын
So I am trying to follow your work but I can't pickup my gun, and I can't find the problem plz help
@fo2sh175
@fo2sh175 4 жыл бұрын
did you find a solution?
@patrickwilliams170
@patrickwilliams170 4 жыл бұрын
I am kinda new to game dev,so please excuse my question if they seem really dumb to you. Is there a way i can make a fully animated character in a project with this system? I ask this because the lack of character/weapon interacting animations and arms makes me think that only a capsule character would work with this. and are hitmarkers possible? I don't mind heavily modding the code,i just dont want to implement a system that i have to completely change.
@Affax
@Affax 4 жыл бұрын
Hmm, that sounds like a big thing. This system wouldn't probably be ready for that, and I would recommend watching another tutorial. And yeah, this tutorial was for simple stuff.
@patrickwilliams170
@patrickwilliams170 4 жыл бұрын
@@Affax ok,thanks.
@recording_closet9100
@recording_closet9100 4 жыл бұрын
why do you put the underscore in front of your variables?
@PagusTheAlpagus
@PagusTheAlpagus 3 жыл бұрын
the underscore is for private variables. It makes it easier to locate them in the script and you don't have to go back to the top of your script to see if the variable is private or public.
@rajsah4667
@rajsah4667 4 жыл бұрын
12:45 I got error CS1002 : ; expected But there is no error I type var forward Vector3 = forward * throwForce; And unity says there is error in this line help??
@Affax
@Affax 4 жыл бұрын
Look in the video. You shouldn't type the Vector 3 there. Because it uses vars you don't need to add the type into the line. Try writing "var forward = forward * throwForce";
@rajsah4667
@rajsah4667 4 жыл бұрын
@@Affax thanks affax but it's so cool if we add hands to this fps it can be looking like csgo or cod u have any idea about it?
@Ybot76
@Ybot76 4 жыл бұрын
Hi, i have a question but im not sure if its answered later on, if i pick up my weapon, it works fine but it messes with the scale slightly, so after picking it up and dropping it 3-4 times it becomes a really thin really long weapon. Does this get explained later on? or did i just make a glitch
@Affax
@Affax 4 жыл бұрын
The parent of the weapon probably isn't 1:1:1 scale. answers.unity.com/questions/790083/object-get-deformed-when-rotating.html
@Ybot76
@Ybot76 4 жыл бұрын
@@Affax Thanks so much
@Ybot76
@Ybot76 4 жыл бұрын
@@Affax ive tried this, but for somereason it isnt working, is their any other reason it may be like this?
@Ybot76
@Ybot76 4 жыл бұрын
Never mind this. I made a new script which fixes the scale issue.
@sonnyfivem
@sonnyfivem 3 жыл бұрын
can i ask why you using this _ in front of some variable ? Thanks.
@Affax
@Affax 3 жыл бұрын
It's just what the C# convention tells us to use It's the "correct" way of writing private variables, though, it doesn't matter what way you write them, I just write them like this)
@sonnyfivem
@sonnyfivem 3 жыл бұрын
Okay, thank you.
@lavinax
@lavinax 4 жыл бұрын
ok im confused i get an error saying "The variable weaponGfxs of weapon has not been assigned" but i get it in weaponmanager what.... im actually so confused
@Affax
@Affax 4 жыл бұрын
You probably haven't assigned the values in the inspector, and it's throwing that error.
@lavinax
@lavinax 4 жыл бұрын
@@Affax yeah i fixed it, had been bugging me for a while... also how do i make like an enemy script
@Affax
@Affax 4 жыл бұрын
Hmm, not sure but there are a lot of cool tutorials on KZbin! (Like Brackeys)
@lavinax
@lavinax 4 жыл бұрын
@@Affax ill try that one and tell u if something wrong happens since ur like my man now
@lavinax
@lavinax 4 жыл бұрын
@@Affax aight i tried but the damage factor doesnt exist, or just doesn't work
@ark854
@ark854 4 жыл бұрын
Can you make a shotgun using this?
@brandonlilly5738
@brandonlilly5738 4 жыл бұрын
When I go to throw my weapon, the rigidbody is no longer on the weapon so it gives me an error. Any tips?
@Affax
@Affax 4 жыл бұрын
If you follow the tutorial, the script removes and adds a Rigidbody, so it is in there
@brandonlilly5738
@brandonlilly5738 4 жыл бұрын
@@Affax Literally after I asked I noticed i was still using GetComponent instead of AddComponent. Appreciate your videos!
@Affax
@Affax 4 жыл бұрын
@@brandonlilly5738 thanks! Im happy you made it work. :D
@acropolise1319
@acropolise1319 4 жыл бұрын
It seems like you are reading from a paper and typing, maybe try explaining more about the code...
@Affax
@Affax 4 жыл бұрын
I explained almost everything about the code (that's why it is 1h 15m) and yes, I read the code from my other monitor because I can't remember all of the code of top of my head. Sorry I didn't explain more.
@acropolise1319
@acropolise1319 4 жыл бұрын
@@Affax everything is fine mate, thanks for the tutorial.
@Affax
@Affax 4 жыл бұрын
@@acropolise1319 Thanks for watching the tutorial! :D
@ved0321
@ved0321 4 жыл бұрын
Hey, great tutorial!! but i have an issue, when i add the weapon camera, i see two guns on my screen, and the one displayed by weapon camera is more sensitive on the y axis. Could you please lemme know if i have made a mistake?
@Affax
@Affax 4 жыл бұрын
You probably didn't disable the weapon layer on the main camera or you didn't add the layer to the weapon object. This should be a huge issue :D
@ved0321
@ved0321 4 жыл бұрын
@@Affax Hey, thanks a lot for the quick reply. That helped me fix the weapon duplicate issue. But i still notice that the weapon gfx layer that appears is quite sensitive to rotation on the y axis. Any suggestions on how to fix that?? thanks again :-) (PS: Im using a different movement script...)
@Affax
@Affax 4 жыл бұрын
@@ved0321 the parent objects sizes have to be uniform (aka 1x1x1). If the height of the parent is 2, them the weapon will be warped.
@Affax
@Affax 4 жыл бұрын
answers.unity.com/questions/1127371/rotating-objects-stretch-horribly-problem.html
@ved0321
@ved0321 4 жыл бұрын
@@Affax Thanks a lot for the help. 😁 Will try it in a while and let you know. You've earned a sub!
@saadblabla
@saadblabla 3 жыл бұрын
Is it just me or is this Dani’s weapon system
@Affax
@Affax 3 жыл бұрын
I've not seen his code (as I've not decompiled it) but the reload animation is the same (i did copy his lol, didn't have time for any better)
@saadblabla
@saadblabla 3 жыл бұрын
@@Affax its alright you can do whatever you want man i wasn’t hating about it, and you should look at his Gun script, its smoother with working headbob. Keep up man, nice work!
@skuggigbuskig402
@skuggigbuskig402 4 жыл бұрын
Is it okay if i use this in a commersial game?
@Affax
@Affax 4 жыл бұрын
Yes
@rxn7
@rxn7 4 жыл бұрын
50:07 after this cut you have added some code in Weapon/Update that you didnt explain
@Affax
@Affax 4 жыл бұрын
Hmm, I didn't cut there, I just exited playmode.
@Danboodles
@Danboodles 3 жыл бұрын
I did it up until 28:22 and the it does let me pick it up but it doesn't let me drop when I press Q, here is the weaponmanager script: using System.Collusing System.Collections.Generic; using UnityEngine; public class WeaponManager : MonoBehaviour { public float pickupRange; public float pickupRadius; public int weaponLayer; public Transform weaponHolder; public Transform playerCamera; private bool _isWeaponHeld; private Weapon _heldWeapon; private void Update() { if (_isWeaponHeld) { if (Input.GetKeyDown(KeyCode.Q)) { _heldWeapon.Drop(playerCamera); _heldWeapon = null; _isWeaponHeld = false; } } else if (Input.GetKeyDown(KeyCode.E)) { var hitList = new RaycastHit[256]; var hitNumber = Physics.CapsuleCastNonAlloc(playerCamera.position, playerCamera.position + playerCamera.forward * pickupRange, pickupRadius, playerCamera.forward, hitList); var realList = new List(); for (var i = 0; i < hitNumber; i++) { var hit = hitList[i]; if (hit.transform.gameObject.layer != weaponLayer) continue; if (hit.point == Vector3.zero) { realList.Add(hit); } else if (Physics.Raycast(playerCamera.position, hit.point - playerCamera.position, out var hitInfo, hit.distance + 0.1f) && hitInfo.transform == hit.transform) { realList.Add(hit); } } if (realList.Count == 0) return; realList.Sort((hit1, hit2) => { var dist1 = GetDistanceTo(hit1); var dist2 = GetDistanceTo(hit2); return Mathf.Abs(dist1 - dist2) < 0.001f ? 0 : dist1 < dist2 ? -1 : 1; }); _isWeaponHeld = true; _heldWeapon = realList[0].transform.GetComponent(); _heldWeapon.Pickup(weaponHolder); } } private float GetDistanceTo(RaycastHit hit) { return Vector3.Distance(playerCamera.position, hit.point == Vector3.zero ? hit.transform.position : hit.point); } } and this is the weapon one: using UnityEngine; public class Weapon : MonoBehaviour { public float throwForce; public float throwExtraForce; public float rotationForce; public int weaponGfxLayer; public GameObject weaponGfx; public Collider[] gfxColliders; private bool _held; private Rigidbody _rb; private void Start() { _rb = gameObject.AddComponent(); _rb.mass = 0.1f; } public void Pickup(Transform weaponHolder) { if(_held) return; Destroy(_rb); transform.parent = weaponHolder; transform.localPosition = Vector3.zero; transform.localRotation = Quaternion.identity; foreach (var col in gfxColliders) { col.enabled = false; } _held = true; } public void Drop(Transform playerCamera) { if(_held) return; _rb = gameObject.AddComponent(); _rb.mass = 0.1f; var forward = playerCamera.forward; _rb.velocity = forward * throwForce; _rb.velocity += Vector3.up * throwExtraForce; _rb.angularVelocity = Random.onUnitSphere * rotationForce; foreach (var col in gfxColliders) { col.enabled = true; } transform.parent = null; _held = false; } }
@Affax
@Affax 3 жыл бұрын
Hmm, you should compare your code with the code I left in the description, probably one line missing.. gl with it!!
@Danboodles
@Danboodles 3 жыл бұрын
@@Affax It all is the same.. Edit: it had to do with the other weapon script, thank you!
@twist474
@twist474 2 жыл бұрын
i was confused about alot of things lol
@V8-Production
@V8-Production Күн бұрын
someone teach me how to make this in godot 😭😭😭😭😭😭😭😭
@potatoman5878
@potatoman5878 4 жыл бұрын
Can somone please tell me if it's working on v2019?
@Affax
@Affax 4 жыл бұрын
I made it in v2019...
@potatoman5878
@potatoman5878 4 жыл бұрын
@@Affax yass,finaly
@recording_closet9100
@recording_closet9100 4 жыл бұрын
@@Affax does the work on v2020?
@antoniomorelli5503
@antoniomorelli5503 4 жыл бұрын
what is your code editor
@Affax
@Affax 4 жыл бұрын
JetBrains Rider
@antoniomorelli5503
@antoniomorelli5503 4 жыл бұрын
@@Affax thanks
@HalldinDEV
@HalldinDEV 4 жыл бұрын
"I will try to get 500 subscribers by the end of the year"
@Affax
@Affax 4 жыл бұрын
Ye... I kinda started to grow faster than I thought. But can't complain XD. The new goal is 2k and I should come close at least!
@ReceptiveRaptor
@ReceptiveRaptor 4 жыл бұрын
I have been trying to make it so that the pistol has a different holder transform than the assault rifle, I've duplicated the Pickup method in weapon.cs and created a PickupPistol method and changed the transform.parent to = pistolHolder; and at the bottom of the Input.GetKeyDown(KeyCode.E)) Method I have added _heldWeapon.PickupPistol(pistolHolder); underneath _heldWeapon.Pickup(weaponHolder); so that it looks like this: _heldWeapon.Pickup(weaponHolder); _heldWeapon.PickupPistol(pistolHolder); I can not seem to (at the moment, I'm looking into it actively) find a way for the script to be like "oh hey that is a pistol!" and "oh hey that is not a pistol!" I will edit this comment if I find a solution that works :). Criticisms: This tutorial is good but very painful to follow along to. Your code text being so small is very headache inducing and not using a more universal IDE (visual studio/community) caused some confusision when following along. Granted you're allowed to use whichever IDE you want, there were just some cases where it caused confusion. Such as at 19:46 at line 25 which says: var hitNumber = Physics.CapsuleCastNonAlloc( "point" playerCamera.position) where as visual studio/community do not have that little word "point". I noticed in the comments you stated your IDE, it might be better moving forward to state that in the video to avoid confusion. Just some (hopefully) constructive criticism, thank you for the tutorial.
@Affax
@Affax 4 жыл бұрын
I already enlargened the font by more than double (and checked in the recording and it was huge) but maybe it was too little. Also, the IDE doesn't really matter in tutorials, I just prefer Rider (because it is better in development). The point things are just visuals, and they do nothing but show the name of the variable (that's why I said point1 and point2). I hoped you could make the scripts work even with these flaws. I won't be making any more tutorials, as I'm trying to transition my channel to more casual audiences (the next video will show what I mean). Thanks for watching.
@gamerweed6949
@gamerweed6949 3 жыл бұрын
Weapon switching?
Unity Basic Weapon System Tutorial
10:47
Plai
Рет қаралды 160 М.
Which Smash Characters have Canonically Smashed?
31:22
PMJ
Рет қаралды 415 М.
An Unknown Ending💪
00:49
ISSEI / いっせい
Рет қаралды 53 МЛН
МАИНКРАФТ В РЕАЛЬНОЙ ЖИЗНИ!🌍 @Mikecrab
00:31
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 42 МЛН
3 Devs Make An FPS - Godot vs Unity vs Unreal || GameDev Battles
12:39
Writing a game the hard way - from scratch using C. #1
34:20
NCOT Technology
Рет қаралды 122 М.
Modeling, Rigging And Animating A Gun In Blender And Unity
14:23
Why 'Aim Down Sights' Is A Bad Mechanic
19:51
ShreddedNerd
Рет қаралды 711 М.
Melee Combat & Weapon System - Unity Beginner Tutorial
20:12
Unity - 2D Melee Combo System Tutorial
22:15
Sean Masai Hill
Рет қаралды 73 М.
I Made The Ultimate Cheating Device
9:39
ChromaLock
Рет қаралды 996 М.
I Wish I Had Known This Before I Started Unity Game Development...
11:11
Infinite Craft is Broken..
33:47
Why Suda
Рет қаралды 1,3 МЛН
ADD ARMS TO YOUR GAME - EASIEST WAY (Unity3D)
15:22
JonDevTutorials
Рет қаралды 58 М.
An Unknown Ending💪
00:49
ISSEI / いっせい
Рет қаралды 53 МЛН