Unity Basic Weapon System Tutorial

Поділитися
Вставка
  • Опубліковано 3 жов 2024

КОМЕНТАРІ • 359

  • @RaddyXD
    @RaddyXD 2 роки тому +91

    When the world needed him the most, he came back

  • @dcry1003
    @dcry1003 2 роки тому +60

    Damn this is very convenient i was just about to continue my 3D project after trying out 2D thank you very much!
    Hey plai can you make a tutorial about melee weapons next like sword swing, throw damage etc.

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

      Just use a short raycast and possibly a delay at the start to compensate for swingtime

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

      @@abel099 that's genius

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

      @@saulgoodman5662 Thanks but that's just how most games do it.

  • @AtLeastITry-j7o
    @AtLeastITry-j7o Рік тому +17

    If anyone has the issue of their weapon facing their camera parallel after trying to implement weapon sway, you're issue may be that when you switched your gun 180 when positioning it, you may have put your sway script in the same directory. For Example, if you changed the direction of your gun in your weapon holder section, and also put the sway script in that same area, and are having this issue, correct the direction of the gun in its folder instead of weapon holder folder.
    Hope this helped anyone who needed it, and sorry if it's kinda confusing I'm not great at explaining things.

  • @zbeb118
    @zbeb118 2 роки тому +6

    Great video can't wait for the following videos about the effects

  • @ZeonplayzYt
    @ZeonplayzYt 2 роки тому +2

    Thanks for coming back

  • @VVIZART_STUDIOS24
    @VVIZART_STUDIOS24 2 роки тому +8

    Amazing !! this was like a whole fps tutorial

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

    thank you so much plai these are the tutorials we need, nice keyboard sound by the way i like it

  • @BatonyRobson
    @BatonyRobson 2 роки тому +3

    Man, thats a extremely good tutorial. Thank you very much. Maximum useful information in minumum time.

  • @reallocal
    @reallocal 2 роки тому +11

    well well well, look who remembered his login.
    good to have you back plai

  • @octopro8937
    @octopro8937 2 роки тому +5

    hey bro great tutorial but can u please help me its says The type or namespace name "Action " could not be found
    (edit) im so dumb unity hating on me not putting "using System;" up at the top but i fixed it no issues

  • @avgchoobafan
    @avgchoobafan 11 місяців тому +6

    7:01 to avoid this, delete the variable currentAmmo from the GunData script and instead put a variable inside Gun named localAmmo.
    In Start() just assign localAmmo to be equal to gunData.magSize.
    Replace gunData.currentAmmo with localAmmo where needed.

  • @aaron4488
    @aaron4488 10 місяців тому +8

    It's therapy for me to watch you code these scripts. It's an art form. Thank you very much for the content. It was better than what I expected.

  • @RatchetEden
    @RatchetEden Рік тому +7

    hi first this is a very good tutorial in the content aspect but its really hard to understand because youre talking both to fast with not enough detail and in monotone making it hard to understand and really boring

  • @KC-ii7rk
    @KC-ii7rk Рік тому

    short and to the point as a dev should be good job best tutorials on yt

  • @kryten719
    @kryten719 2 роки тому +1

    New video!!!
    Hype

  • @dipsheet1650
    @dipsheet1650 2 роки тому +5

    Hey man! Great tutorial! Could make a follow up video showing us how to add animations to the gun?

  • @hyperz737
    @hyperz737 2 роки тому +4

    can U make a video on crouching and sliding on ur character movement scripts.

  • @RealRenixGaming
    @RealRenixGaming 2 роки тому +8

    Amazing videos, you probably know how hard it was to start game developing and right now that is me, thank you for helping. 🤗

  • @spidernh
    @spidernh 2 роки тому +3

    how convinient, I opened unity for the first time in a while yesterday to try and recreate an old game that was supposed to have weapons (wasn't smart enough back then)
    I'm still gonna use my terrible system but probably do something similar to your damage interface

  • @Jeast.
    @Jeast. Рік тому +5

    Thanks for this, its been really fun making shotguns, assault rifles and pistols using this script, youre a really big help to the indie devs.

  • @NikoVReality
    @NikoVReality 2 роки тому +6

    Great! It was not ok for me to use a Raycast, 1-st because of my gun in the center of the screen (so it was always a "target" for cameras), and 2-nd I wanted a physical bullet, but not a "virtual" one. So I mixed your code with some other simple features, worked perfect!!!

    • @MennoWeerman
      @MennoWeerman 2 роки тому +1

      what other features for the visual bullet?

  • @Solidrigs
    @Solidrigs 2 роки тому +6

    Dude you are the only guy that actually deserves all sub, like and alarm buttons, truly worthy contents.

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

    There is something strange in the WeaponSway script, it turns my weapon 180 degrees facing me. please help

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

    i got everything else working but the shooting it doesn't work for me

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

    I am getting two errors, one says "error CS0106: The modifier 'public' is not valid for this item" and the other says "error CS0535: 'Target' does not implement interface member 'IDamageable.Damage(float)'
    I also get an error when I try to add the target script to the target object, that reads "Can't add script component 'Target' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match."
    Please help, I've been trying to fix this for ages to no avail. The 'public' in "public void damage(float damage);" inside IDamageable is uncolored in visual studio so that seems to be part of why it's not working.

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

      If you have the error "cs0106 " The modifier 'public' is not valid for this item ,
      simply delete the public should keep this =
      void TakeDamage(float damage);

  • @octopro8937
    @octopro8937 2 роки тому +3

    hey this vid great and i love it but if anyone got any errors that say something like muzzle variable or muzzle not assigned just go to your gun's inspector then where it says transform select your muzzle then no error

  • @randomdud581
    @randomdud581 2 роки тому +3

    Can anyone pls help? When I drag the Scriptable object into Gun data field, it shows that it should be the same class name.
    By the way nice video!

    • @plaidev
      @plaidev  2 роки тому

      Thanks! Maybe the name of the file and the name of the class are different? They should be the same.

  • @ipga13
    @ipga13 2 роки тому +7

    nice and fast, to the point, no unneccasary explaining. perfect! wish every tutorial was like this.
    edit: suggestion maybe an interaction system

    • @gerblesh_674
      @gerblesh_674 2 роки тому +1

      not hard to code, legit just takes some simple triggers and input detection

    • @jakes-dev1337
      @jakes-dev1337 Рік тому

      ​@@gerblesh_674 you are on a tutorial...

  • @vampire1256
    @vampire1256 2 роки тому +1

    "type or namespace name 'IDamageable' could not be found" tf do i do here

  • @gabrielx24_44
    @gabrielx24_44 2 роки тому +1

    🧿
    Awesome tutorial

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

    on the script gun I got error CS0103 the type or namespace name "Damageable" could not be found twice at 15,9 and 16,9 and then it says. the name 'Playershoot'
    does not exist in current context what do I do.
    I'm using notepad by the way.

  • @garfield6482
    @garfield6482 2 роки тому

    Plai is Back

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

    For some reason the Game Object even when I have these in and have no errors
    Target.cs
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class Target : MonoBehaviour, IDamageable
    {
    private float health = 100f;
    public void Damage(float damage)
    {
    health -= damage;
    if (health

  • @LumpieMilk
    @LumpieMilk 2 роки тому +3

    Nice video actually showing you a more modular weapon system rather than just showing you how to do a raycast and that's it, like most other tutorials. My spaghetti code thanks you

  • @Observer552
    @Observer552 Місяць тому

    Can you please make a video explaining all these things in more detail? Because just copying and pasting doesn't help much. It might help a little bit, but learning what these things do (at least the things I don't understand) is more efficient.

  • @theplayergt231
    @theplayergt231 25 днів тому

    btw weapon sway
    using System;
    using UnityEngine;
    public class WeaponSway : MonoBehaviour
    {
    [Header( "Sway settings")]
    [SerializeField] private float smooth;
    [SerializeField] private float multiplier;
    private void Update()
    {
    float mouseX = Input.GetAxisRaw("Mouse X") * multiplier;
    float mouseY = Input.GetAxisRaw("Mouse Y") * multiplier;
    Quaternion rotationX = Quaternion.AngleAxis(-mouseY, Vector3.right);
    Quaternion rotationY = Quaternion.AngleAxis(mouseX, Vector3.up);
    Quaternion targetRotation = rotationX * rotationY;
    transform.localRotation = Quaternion.Slerp(transform.localRotation, targetRotation, smooth * Time.deltaTime);
    }
    }

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

    How do I set the reload key by default to be R?

  • @gl1tchvr.
    @gl1tchvr. 25 днів тому

    i need help, when i put thre muzzle stuff in i got this error message: "Assets\scripts\Gun.cs(28,39): error CS1061: 'RaycastHit' does not contain a definition for 'muzzle' and no accessible extension method 'muzzle' accepting a first argument of type 'RaycastHit' could be found (are you missing a using directive or an assembly reference?)" is there any way to fix this?

  • @EpicP1xel
    @EpicP1xel 6 місяців тому +1

    Waste of time so bad

  • @monkmonkeen1531
    @monkmonkeen1531 2 роки тому +1

    I'm getting an error saying Target.cs(5,14), error CS0101, global namespace already contains a defintion for 'Target'

  • @neilb5007
    @neilb5007 2 роки тому +4

    this tutorial is great but i cant figure out how to make semi automatic weapons how do I reference the gundata scriptable object in the player shoot script to check if a weapon is automatic or not so that if it is semi automatic it only shoots when the mouse is pressed once

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

    Thanks for the nice tutorial! Just a quick question here!
    I'm wondering what's the main difference of making "gun script" with every variable in the "gun data script" and attach it to each weapon and change the parameter, versus doing exactly what you did in the video where you make "gun data" a scriptable object and use those variables in the "gun script"? I'm interested in mastering OOP and Scriptable Object more so I'd love to learn the advantage of doing the latter method!

  • @CrammyCram
    @CrammyCram 2 місяці тому +1

    I like how you actually tell us what we're scripting instead of just showing us what to write down

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

    how would you do the shooting button for a ps4 controller right trigger

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

    thanks!

  • @Hyphen3372
    @Hyphen3372 2 роки тому

    ay new vid very nice and helpfull

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

    How can i learn code, i want be good just like you

  • @JelowGames
    @JelowGames 2 роки тому +1

    multi-player fps parkour. or don't you probably don't know how to 😂

    • @qaswer_kaiser
      @qaswer_kaiser 2 роки тому

      he's not dani you can't tempt him like that

  • @plaidev
    @plaidev  3 місяці тому

    I realized I accidentally wrote `TakeDamage` instead of `Damage` at the end there. Sorry about that.

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

    I keep getting an error saying the type namespace name ‘action’ could not be found

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

      if you look at the top of your script there's a bunch of lines says using etc under using unityengine put this:
      using System;

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

      @@melamri6640 ok

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

      @@melamri6640 Thanks for this

  • @MrPotatoKing388
    @MrPotatoKing388 2 роки тому +3

    ive been trying for 2 hours to find out what and how to use pivot mode is

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

    for me it says The modifier 'private' is not valid for this item for the private void update is there anyway to fix this?

  • @Birb-bc2jw
    @Birb-bc2jw Рік тому +2

    Great Vid but can you help me with something, when i do this - [SerializeField] GunData gunData; it doesnt show me the section to put gun data

  • @EduEdo27
    @EduEdo27 2 роки тому +1

    I've followed every step but my gun still ain't reloading

  • @Tybek1
    @Tybek1 2 роки тому

    Yay its Plai

  • @AhmedMohamed-h3e
    @AhmedMohamed-h3e Рік тому +1

    hey gus i've just started a game project and in 4:42 i don't understand anything and unity gives me an error : Playershoot does not contain a definition for shootinput

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

    At 10:28 you type damagable?.TakeDamage(gunData.damage); but there is no reference for TakeDamage in IDamageable.
    I'm pretty sure you just meant the void "Damage" you created at 10:08 because I used it instead and it worked.
    Feel free to correct me.

  • @TheNuuttiPro123
    @TheNuuttiPro123 2 роки тому +1

    Will you remember me when you are famous?

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

    I have a question , what version of unity will this work on?.

  • @york9283
    @york9283 2 роки тому +2

    Sprint and crouch system please!

  • @Hye.3346
    @Hye.3346 Рік тому +3

    using System;
    using UnityEngine;
    public class WeaponSway : Monobehaviour {
    [header("Sway Settings:)]
    [SerializeField] private float smooth;
    [SerializeField] private float multiplier;
    private void Update()
    {
    // get mouse input
    float mouseX = Input.GetAxisRaw("Mouse X") * multiplier
    float mouseY = Input.GetAxisRaw("Mouse Y") * multiplier
    // calculate target rotation
    quaternion rotationX = Quaternion.angleAxis(-mouseY, Vector3.right);
    Quaternion rotationY = Quaternion.AngleAxis(mousex, vector3.up);
    quaternion targetRotation = rotationX * rotationY;
    //rotate
    transform.localRotation = quaternion.slerp(transform.localrotation, targetRotation, smooth * Time.deltaTime);
    }
    )
    script :D

  • @xzippyzachx
    @xzippyzachx 2 роки тому +1

    PEW PEW PEW

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

    once i complete the final step of the tutorial and save my code, it says that "TakeDamage" is not something it identifies it, was there somewhere I was supposed to reference it

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

      change "TakeDamage" to just "Damage"

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

      @@westron7257 That didn't work for me

  • @practicemakinganimation
    @practicemakinganimation Місяць тому

    Thank you so much bro, can you do about melee or combat system

  • @bingchilling989
    @bingchilling989 2 роки тому +2

    does the raycast always hit anything that is on the middle of the screen (crosshair) even if it is on the muzzle which is offset from the middle

    • @caution0001
      @caution0001 2 роки тому

      Not neccesarily, Personaly i would cast a ray from the forward direction of the camera to have consistancy between all weapons and where they aim.
      This way, you also have more freedom to position the weapon how you want so it looks better in the camera view

    • @plaidev
      @plaidev  2 роки тому

      Yea as @C4uTi0N said it won't hit the centre of the screen. Depending on the position of the gun it'll be slightly offset. If you would like it to be exactly the centre you can use the camera's position as the origin and the camera's forward as the direction of the Ray.

    • @bingchilling989
      @bingchilling989 2 роки тому

      Ok Thx

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

    May GOD Bless you ❤

  • @StupidDuckDev
    @StupidDuckDev 2 роки тому +1

    How do I get the weapon sway code to work with an animator?

  • @zephyr-d7v
    @zephyr-d7v 2 роки тому +1

    Hello! At the start of the video when you add the sway, mine worked, but also did not work. What happened was the sway is there but it turned my gun sideways??? How can you help???

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

      There is line with float MouseX
      In MouseX after the swayMultiplier change it to -360f (idk you need to test)

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

      Also in Quaternion rotation X change last few words to (mouseY, Vector3.left

  • @Heroicplayzrbx
    @Heroicplayzrbx 3 місяці тому

    I have a error in Gundata what do I do

  • @Nitrobeat
    @Nitrobeat Місяць тому

    i cant get it to work helpppppppp

  • @buzzyrobo
    @buzzyrobo 2 роки тому +1

    What is the font you use in your intro and other text?

  • @YeagerStinky
    @YeagerStinky 23 дні тому

    If only I had unity

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

    can anyone explain why my gun doesnt move in directions, theres no error in the console, it just doesnt move with my mouse

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

    I can't do the shoot cause the Action variable is not working

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

    it is showing me this error Assets\Scripts\Gun.cs(50,77): error CS0246: The type or namespace name 'IDamageable' could not be found (are you missing a using directive or an assembly reference?) Pls help!

  • @hehehe_hussain1694
    @hehehe_hussain1694 18 днів тому

    in the playershoot script im getting this error:
    Assets\PlayerShoot.cs(8,19): error CS0246: The type or namespace name 'Action' could not be found (are you missing a using directive or an assembly reference?)

    • @fireburst6868
      @fireburst6868 7 днів тому

      Please show your code, because I had the same issue but cant remember how I solved it

    • @hehehe_hussain1694
      @hehehe_hussain1694 6 днів тому

      @@fireburst6868 i already solved it i just asked chat gpt

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

    Does somebody know why when i write the [CreateAssetMenu part it gives me CS1012 which is too many charecters in literal and i try the softwares fixes which didnt work so does anybody know a fix?

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

    i get an error on the last line of code for 'TakeDamage' plz some one help it says theres no reference to it

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

      @Dev I fixed It a long time ago

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

    Can someone help me? im having a issue with the code. im getting this error: "Assets/Scripts/IDamageable.cs(8,17: errorCS0106: the modifier 'public' is not valid for this item"
    I have no idea what it means

  • @ToprakDev_Games
    @ToprakDev_Games 2 роки тому +1

    Thank :)

  • @minT-Toas
    @minT-Toas 2 місяці тому

    how do you add sounds

  • @Messiahs100
    @Messiahs100 2 роки тому +1

    A realy great Video Plai ! But i stuck :_( I get the error message " Target' does not implement interface member 'IDamageable.Damage()' " and i dont get the red lines in the visual studio to folow your steps. 😞

  • @Rahulsingh-theraha
    @Rahulsingh-theraha 2 роки тому +1

    I understand everything on first try ,that is just brilliant man

  • @speedz7563
    @speedz7563 2 роки тому +1

    plai when are you gonna make your own game?

    • @plaidev
      @plaidev  2 роки тому +1

      I ask myself the same question 😩

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

    Help!! When I get collide with wall or anyother object, the raycast goes through and draw the line and won't damage the enemies, how can I fix it?

  • @anj_10
    @anj_10 2 роки тому +1

    Your the best,Thanksss

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

    If you have the error "cs0106 " The modifier 'public' is not valid for this item ,
    simply delete the public should keep this =
    void TakeDamage(float damage);

  • @strompy2007
    @strompy2007 2 роки тому +1

    Yesss he comes back!

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

    Helpful

  • @dsguy369ds6
    @dsguy369ds6 2 роки тому +1

    bro im so glad your making videos, there so good haha

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

    it wont shoot

  • @SaharshDev
    @SaharshDev 2 роки тому +1

    YOO PLAI NEW VID LESS GOO

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

    error CS0246: The type or namespace name 'IDamageable' could not be found (are you missing a using directive or an assembly reference?

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

    The game is telling me that the modifier 'public' on the IDamageable script is not valid for the item, can anyone help?

  • @bogalok588
    @bogalok588 3 місяці тому

    ty so much

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

    HOW DO U ENTER PIVOT MODE

  • @actuallyalex9812
    @actuallyalex9812 2 роки тому

    Says that error CS0246: The type or namespace name 'RangedWeapons' could not be found (are you missing a using directive or an assembly reference?)
    (I renamed it to ranged weapons cause imma add melee weapons after)
    even though its right there! thanks for taking your time if you'd like to help.

  • @chief_9745
    @chief_9745 2 роки тому +1

    when i write the playershoot unity gives an error for action plz help

    • @flieshunter1424
      @flieshunter1424 2 роки тому

      same for me

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

      You have to put "using System;" at the top of the script. its there in his video, but never called out so its easy to miss

  • @anis6674
    @anis6674 2 роки тому

    can you slow down pls your saying stuff i never heard of in my life like they're obvious

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

    the "TakeDamage" thing is causing an Error, it is not variable or declared

    • @jaysonpirang9827
      @jaysonpirang9827 3 місяці тому

      did you find a fix?

    • @jaysonpirang9827
      @jaysonpirang9827 3 місяці тому

      ohh i just found another comment that says this "take the Damage function and just change its name to TakeDamage
      ". it works!!! (hope it helps) :)