How to make 2D Shooting in UNITY with Gun Recoil - Unity 2D

  Рет қаралды 35,216

The Game Guy

The Game Guy

Күн бұрын

Consider donating to help me keep this channel and website alive : paypal.me/supportTheGameGuy 💖
or Support me on Patreon : / the_game_guy
In this video im gonna show you how to fire 2d gun and also add effects to make it look cooler, And add a recoil to our gun to add a nice feel to it.
In this tutorial i will tell you everything you need to know to make your very first 2D gun in unity and make it AWESOME.
To download EZ Camera Shake : github.com/andersonaddo/EZ-Ca...
and here are some more tutorials which might be useful :
How to throw knife in UNITY :
• How to throw knife usi...
How to make an AWESOME game Menu :
• How to make an AWESOME...
How to make level saving System :
• How to make a simple L...
Remote Configuration by BRACKEYS :
• CHANGE YOUR GAME ANYWH...
Game difficulty by Brackeys :
• Difficulty in Video Ga...
How to make first person game in UNITY by BRACKEYS :
• MAKING YOUR FIRST FPS ...
Some interesting and fun Unity videos by DANI
I made an evil bot my friend :
• I Accidentally Made an...
I turned KZbin into giant battle royal game :
• I Turned KZbin into ...
I made a game in 30 Minutes :
• Making a Game in 30 Mi...

Пікірлер: 109
@TheGameGuy
@TheGameGuy 3 жыл бұрын
For the Copy/Paste gang 😜 Grab the assets from : thegameguy.net/resources.html
@brejnastore
@brejnastore 3 жыл бұрын
how to destroy bullet on trigger with sth?
@Winsomnia
@Winsomnia 3 жыл бұрын
its not there. can you add a paste bin link?
@jackeygaming7454
@jackeygaming7454 Жыл бұрын
Sir can you make this in unity bolt love you and this is a request
@dontCallMe..
@dontCallMe.. Жыл бұрын
the website dont work why
@lapezi
@lapezi 2 жыл бұрын
Thank you so muchhh!!!! This is the exact thing I needed for my game!! YOU ARE AWESOME!!!!!!!!
@alialaei1554
@alialaei1554 Жыл бұрын
Your video was exactly what I needed. You couldn't use this 13 minutes better.
@jaimezapatagomez
@jaimezapatagomez 4 жыл бұрын
Thanks great tutorials, keep it up. I cannot understand why your channel does not have more subscribers, you deserve more. I have to say that was a little bit hard to find your channel but it is full with good info.
@TheGameGuy
@TheGameGuy 4 жыл бұрын
jaime zapata Thank you bro means alot ❤
@pedror1439
@pedror1439 3 жыл бұрын
i thought it was gonna be actual recoil not an animation, but still thanks for the tutorial
@bobbville
@bobbville 2 жыл бұрын
This video is cool, I just wish there were more updated versions of this out there
@GhostYassin
@GhostYassin 4 жыл бұрын
Thank you for this nice tutorial! i have a question, how can i mirror the gun if i aim to the left direction?
@michaelpavlov4908
@michaelpavlov4908 4 жыл бұрын
Awesome Tutorial
@cryelectric
@cryelectric 10 ай бұрын
Wow Wow Wow! Thank you very mutch!
@amerging8687
@amerging8687 2 жыл бұрын
Thanks to you Please continue this Amazing work 😍😍😍😍🥰🥰🥰🥰🥰
@Amazicat
@Amazicat 4 жыл бұрын
Bro you deserve more views and subs, love your vids man
@TheGameGuy
@TheGameGuy 4 жыл бұрын
Thanks Mate
@Couldbeme
@Couldbeme 2 жыл бұрын
can you give me the code mine's not working so i want to copy and paste it to see if it will work
@RHCIPHER
@RHCIPHER 3 жыл бұрын
the god dam best
@TheGameGuy
@TheGameGuy 4 жыл бұрын
Skip to particular time : Add a Gun - 0:40 Shooting Script - 1:48 FireRate - 6:58 Adding Recoil : 8:56 Screen Shake : 13:22
@IheartGames646
@IheartGames646 Жыл бұрын
cool tutorial but ive a question, i have a simple player script and hes sprite flips when facing left or right, the gun is facing right but when i face left the gun flips upside down how do i fix this??
@cdkw8254
@cdkw8254 3 жыл бұрын
This is what you call a detailed tutorial.
@cdkw8254
@cdkw8254 3 жыл бұрын
Hey bro can you make a gun which has more settings like load time, Bullet Speed, Gun Changing System, Bullets left, Recoil for the player Bullet spread and etc ????
@Couldbeme
@Couldbeme 2 жыл бұрын
can you give me the code mine's not working so i want to copy and paste it to see if it will work
@Anyways-bi6nq
@Anyways-bi6nq 3 жыл бұрын
how can you make your shoot point change and everything change when you turn left or right?
@bahadrizgi6589
@bahadrizgi6589 3 жыл бұрын
why people disliked this video this video is very very good thanks dude :)
@casianprox310
@casianprox310 Жыл бұрын
Nice video keep it up
@piotrzyla5111
@piotrzyla5111 3 жыл бұрын
great job, Works perfectly! The only thing I had was to get correct world mouse position (I worked on 2D template) but I found solution and it works fine. For those who will encounter problem that gun won't track mouse coursor, use this in the Update() method: Vector3 mousePos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -Camera.main.transform.position.z)); direction = (Vector2)mousePos - (Vector2)Gun.position; cheers!
@astroidfrog644
@astroidfrog644 Жыл бұрын
Thank you for this! I worked for 5 hours to get the gun to rotate correctly, and you found my problem!
@user-zt7es1mo9t
@user-zt7es1mo9t 3 жыл бұрын
Thanks
@Bo_KLR
@Bo_KLR 3 жыл бұрын
3:08 'Input' does not contain a definition for 'mousePosition' How to fix it?
@kaizu_2893
@kaizu_2893 3 жыл бұрын
thanks a lot
@kbenskeer5071
@kbenskeer5071 4 жыл бұрын
great tutorial but what do i need to do when i want to flip the gun sprite so the gun is not upside down?
@brejnastore
@brejnastore 3 жыл бұрын
@@taj2163 Bruh, when you point other direction (back) gun is upside down
@SpeedLuffy
@SpeedLuffy 3 жыл бұрын
there is a problem when i flip player the offset of gun also get affected.
@alexandruaioanei7457
@alexandruaioanei7457 3 жыл бұрын
did U solve it? I have the same problem
@kevinneff3285
@kevinneff3285 3 жыл бұрын
Great tutorial!
@__navv
@__navv 3 жыл бұрын
How can i clamp the gun rotation?
@gearsunrayy
@gearsunrayy 2 жыл бұрын
Does anybody know why my gun does not look at the mouse anyway when I put the code in???
@galberger3937
@galberger3937 Жыл бұрын
Hi. How to pickup the gun and then shoot?
@ulti-corn7882
@ulti-corn7882 2 жыл бұрын
Game Guy i have a problem with making the bullet function its based on this part: GameObject BulletIns = Instantiate(Bullet,ShootPoint.position,ShootPoint.position,ShootPoint.rotation); and here are the 2 errors: Assets\Shoot.cs(43,71): error CS1503: Argument 3: cannot convert from 'UnityEngine.Vector3' to 'UnityEngine.Quaternion' Assets\Shoot.cs(43,91): error CS1503: Argument 4: cannot convert from 'UnityEngine.Quaternion' to 'UnityEngine.Transform'
@zhabiboss
@zhabiboss 2 жыл бұрын
Uh, I have a bad resolution, and I get an error of Instantlate does not exist in current context, maybe I spell it wrong?
@ilydes
@ilydes 3 жыл бұрын
For some reason i get an error about not knowing the mouseposition
@jackeygaming7454
@jackeygaming7454 Жыл бұрын
Sir can you make this in unity bolt love you and this is a request
@mikoajtworzy3157
@mikoajtworzy3157 Жыл бұрын
hello can you do tutorial for reload please
@lucineialufiel644
@lucineialufiel644 2 жыл бұрын
How to Flip the gun If It is behind the player
@100notpenguin8
@100notpenguin8 2 жыл бұрын
i have a script to flip the character when moving left or right how do i make the gun not also flip
@gnrinried
@gnrinried Жыл бұрын
have you found it out?
@kaliexdtube6311
@kaliexdtube6311 2 жыл бұрын
when i shoot the bullet not move
@_NaKnow
@_NaKnow 11 ай бұрын
you save my lift
@ChuckFish
@ChuckFish 3 жыл бұрын
Hi I hope you get this i need help. So in the gun script when you add force to the right, but my charactermovement script changes the direction the player is facing but when i shoot the gun the bullets still shoot right can you please help?
@rmurphy6830
@rmurphy6830 2 жыл бұрын
Hi, how you solved it?
@ChuckFish
@ChuckFish 2 жыл бұрын
@@rmurphy6830 uhh I forget. I did something where the gun is attached to the player I believe
@ChuckFish
@ChuckFish 2 жыл бұрын
@@rmurphy6830 so I just checked. In my character movement script I have it so that my character flips when “a” and “d” are pressed so when I put the gun attached to the played the gun also flips with the player.
@RHCIPHER
@RHCIPHER 3 жыл бұрын
the best
@SDSFDSF631
@SDSFDSF631 2 жыл бұрын
What about damage???
@Bo_KLR
@Bo_KLR 3 жыл бұрын
What movement script you use?i cant find script that works with jump
@FortniteBalls9669
@FortniteBalls9669 3 жыл бұрын
here is my script: using UnityEngine; public class Playerscript : MonoBehaviour { public float movementSpeed = 1; public float JumpForce = 1; private Rigidbody2D _rigidbody; private void Start() { _rigidbody = GetComponent(); } private void Update() { var movement = Input.GetAxis("Horizontal"); transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * movementSpeed; if (!Mathf.Approximately(0, movement)) transform.rotation = movement > 0 ? Quaternion.Euler(0, 180, 0) : Quaternion.identity; if (Input.GetButtonDown("Jump") && Mathf.Abs(_rigidbody.velocity.y) < 0.001f) { _rigidbody.AddForce(new Vector2(0, JumpForce), ForceMode2D.Impulse); } } }
@FortniteBalls9669
@FortniteBalls9669 3 жыл бұрын
Hope it helps
@_mrcreep_3539
@_mrcreep_3539 3 жыл бұрын
Hello, I have Playermovement script which flips him based on his position. Well the gun is now flipping too. Can you please help me ho to avoid this bug? Thanks :)
@alexandruaioanei7457
@alexandruaioanei7457 3 жыл бұрын
Hi did u solve it because I have the same error and I don t know how to solve it
@_mrcreep_3539
@_mrcreep_3539 3 жыл бұрын
@@alexandruaioanei7457 well you have to make empty game object and separate uder this object GunHolder and Player it self.... so you will have game object -weapon -player
@alexandruaioanei7457
@alexandruaioanei7457 3 жыл бұрын
@@_mrcreep_3539 thanks a lot
@_mrcreep_3539
@_mrcreep_3539 3 жыл бұрын
@@alexandruaioanei7457 no problem
@gnrinried
@gnrinried Жыл бұрын
​@@_mrcreep_3539 this doesnt work for me
@FortniteBalls9669
@FortniteBalls9669 3 жыл бұрын
I need help. How do I have the gun turn to the left when the player faces the left?
@ballkicker2391
@ballkicker2391 3 жыл бұрын
I have the same issue
@ajahshwhs
@ajahshwhs 2 жыл бұрын
Did you fix it? if not heres a yt link on how to do it change all the transforms to your gun kzbin.info/www/bejne/bJnTamCjqNGVsKs
@koolstof_
@koolstof_ 3 жыл бұрын
Can you make a tutorial about an enemy? And thanks for the great tutorials!
@sams3791
@sams3791 3 жыл бұрын
no
@Couldbeme
@Couldbeme 2 жыл бұрын
can you give me the code mine's not working so i want to copy and paste it to see if it will work
@nigmft4752
@nigmft4752 2 жыл бұрын
this work for 3d
@wat6482
@wat6482 3 жыл бұрын
Hey Can You Make A Pick Up Item Toturial Pls Help Me :(
@raidoksgames3510
@raidoksgames3510 3 жыл бұрын
Yes please
@nthirumaleshkumar4056
@nthirumaleshkumar4056 3 жыл бұрын
can anybody know the gun work for 3D game
@jasielt.2006
@jasielt.2006 3 жыл бұрын
I'm trying to fo the same thing you are, I just thought of switching all of the 2d components in the script to normal components and skipping the mouse look stuff it might work idk
@biimyflipps
@biimyflipps 2 жыл бұрын
it does not work pls help
@jabbuergamer7162
@jabbuergamer7162 3 жыл бұрын
how to add damage ?
@TheGameGuy
@TheGameGuy 3 жыл бұрын
Adding damage to your enemies is fairly easy : firstly inside of OnCollisionEnter2D method in enemy script check if the gameobject that has collided with the enemy has a tag of bullet and if so just call some damage method that decreases the health of your enemy.
@Rayan-bk3fn
@Rayan-bk3fn 3 жыл бұрын
how do I download Ez- Camera - shake
@TheGameGuy
@TheGameGuy 3 жыл бұрын
You can find the link in the description.
@Real-Hoodie-Guy
@Real-Hoodie-Guy 3 жыл бұрын
Soooo my bullet is not showing up is there any way to fix this?
@TheGameGuy
@TheGameGuy 3 жыл бұрын
is it appearing in the hierarchy?? if it is then maybe you need to bump up the sorting layer on the bullet sprite renderer.
@brejnastore
@brejnastore 3 жыл бұрын
@@TheGameGuy i had the same problem bullet was rotated 90 degree in X so in 2D you cant see it XD
@Rayan-bk3fn
@Rayan-bk3fn 3 жыл бұрын
is MosuePosition for mobile?
@TheGameGuy
@TheGameGuy 3 жыл бұрын
Yes, it works the same exact way.
@Rayan-bk3fn
@Rayan-bk3fn 3 жыл бұрын
@@TheGameGuy Thanks
@jamescraft5300
@jamescraft5300 Жыл бұрын
it does not show up on your website
@KahootSucks
@KahootSucks Жыл бұрын
Just follow the tutorial you fucking script kiddie
@bobjohnson9828
@bobjohnson9828 3 жыл бұрын
How do I make the bullet get destroyed after hitting something
@MaxiMannor
@MaxiMannor 3 жыл бұрын
you will have to use an OnTriggerEnter2D function, make sure the collider on you bullet prefab is a trigger (tick the "is trigger" box) and then write something like this: void OnTriggerEnter2D(Collider2D hitInfo) { Destroy(Gameobject); } If you want the bullets to dissapear after some time to not clutter up the heirarchy you can type the same thing in the start function: void Start() { Destroy(GameObject, 10f) } if your player has a collider, make sure that the bullets and the player are on different layers so that the bullet wont collide with the player go to project settings (edit, project settings) and look for the layer collision matrix, tick the box that matches the bullet layer with the player layer so that its disabled. hope this helps
@brejnastore
@brejnastore 3 жыл бұрын
@@MaxiMannor Function is declared but never used, some fix?
@MaxiMannor
@MaxiMannor 3 жыл бұрын
@@brejnastore make sure you actually have a collider thats set to trigger on your bullet. it should work just fine
@brejnastore
@brejnastore 3 жыл бұрын
@@MaxiMannor i have colliders when i shoot bullet bounce of other colliders :(
@MaxiMannor
@MaxiMannor 3 жыл бұрын
@@brejnastore is your collider on you bullet (not the others) set to trigger? Make sure you have ticked the "is trigger" box on the collider component
@croissantman1738
@croissantman1738 2 жыл бұрын
4:05
@darijus4094
@darijus4094 8 ай бұрын
Script (excluding camera shake) using System.Collections; using System.Collections.Generic; using UnityEngine; public class shootScript1 : MonoBehaviour { public Transform Gun; Vector2 direction; public Animator gunAnimator; public GameObject Bullet; public float BulletSpeed; public Transform ShootPoint; public float fireRate; float ReadyForNextShot; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); direction = mousePos - (Vector2)Gun.position; FaceMouse(); if(Input.GetMouseButton(0)) { if (Time.time > ReadyForNextShot) { ReadyForNextShot = Time.time + 1/fireRate; shoot(); } } } void FaceMouse() { Gun.transform.right = direction; } void shoot() { GameObject BulletIns = Instantiate(Bullet,ShootPoint.position,ShootPoint.rotation); BulletIns.GetComponent().AddForce(BulletIns.transform.right * BulletSpeed); gunAnimator.SetTrigger("Shoot"); //how long the bullet lasts Destroy(BulletIns,1); } }
@vibec7855
@vibec7855 5 ай бұрын
thx
@ivandoesnotcare.8357
@ivandoesnotcare.8357 3 жыл бұрын
Can you copy and paste the shoot script in the comments? I keep Messing it up.😡😡😡
@coswic9128
@coswic9128 Жыл бұрын
this is fake recoil, i want a recoil that actually pushes the player towards the oposite direction of were u shoot the bullet
@aayankerin5628
@aayankerin5628 9 ай бұрын
Activate Windows
@Rayan-bk3fn
@Rayan-bk3fn 3 жыл бұрын
Thanks
How To Make Any Game Mechanic - Episode 7 - 2D Grappling Hook
15:53
ThatOneUnityDev
Рет қаралды 4,1 М.
ДЕНЬ РОЖДЕНИЯ БАБУШКИ #shorts
00:19
Паша Осадчий
Рет қаралды 6 МЛН
NO NO NO YES! (50 MLN SUBSCRIBERS CHALLENGE!) #shorts
00:26
PANDA BOI
Рет қаралды 102 МЛН
Joven bailarín noquea a ladrón de un golpe #nmas #shorts
00:17
How To Ledge Climb in Unity
27:00
AlexDev
Рет қаралды 18 М.
3 Ways to Shoot Projectiles in Unity!
23:07
Code Monkey
Рет қаралды 238 М.
Unity Tutorial: Realistic Shooting using Raycasting
7:58
PitiIT
Рет қаралды 17 М.
HOW TO MAKE SPRITES & SPRITESHEETS FREE USING GIMP
21:09
timbosinfo
Рет қаралды 12 М.
How to make an enemy follow player - Unity NavMesh
3:57
Create Shooting Sound in 2D Unity game
2:09
Nathan Jenkins
Рет қаралды 2,9 М.
I created the PERFECT grappling hook... and you can too! UNITY 2D
10:43
2D Movement in Unity (Tutorial)
21:09
Brackeys
Рет қаралды 3 МЛН
⁠free win with @Toodyxz  😎
0:31
Rzm64
Рет қаралды 2,4 МЛН
#Roblox но моя сестра в ярости от такого подарка..🫣 #Lipt04ka
0:36
Липточка | РОБЛОКС
Рет қаралды 1,4 МЛН