Unity: 2D Shooting

  Рет қаралды 44,375

Root Games

Root Games

2 жыл бұрын

Learn how to shoot in Unity 2D with simple usage of the new input system. For more detailed explanation of the new input system see my Udemy course and learn faster:
✅ Get my courses with discount:
👉 Unity 2D Master: www.udemy.com/course/unity2dm...
👉 Unity Mobile Course: www.udemy.com/course/unitymob...
👉 Unity Input System with Rebinding: www.udemy.com/course/unity-in...
👍 Save your time and learn Unity faster
-------------------------------------------------------
🔔 Subscribe for more awesome content:
🔴 / @rootgames
-------------------------------------------------------
🟡 Support this channel through donations
Any amount means a lot and will help grow the channel:
👉 PayPal: www.paypal.com/paypalme/rootg...
-------------------------------------------------------
Social Networks:
⭐ Instagram: / rootgamesofficial
⭐ Twitter: / rootgamescro
⭐ TikTok: www.tiktok.com/@rootgamesoffi...
⭐ Facebook: / root-games-10337038860...
-------------------------------------------------------
#unity2d #unitytutorial #unityshooting

Пікірлер: 89
@RootGames
@RootGames 2 жыл бұрын
HINT: If your bullets move too fast, sometimes collision can't be detected. Select your bullet prefab and in Rigidbody settings, set Collision Detection to "Continuous"
@anmol9864
@anmol9864 2 жыл бұрын
good bro help me a lot
@cursedkennedy7605
@cursedkennedy7605 3 ай бұрын
My bullets are moving too slow
@user-fm5mn5pq3e
@user-fm5mn5pq3e Жыл бұрын
This tutorial was amazing. Thank you a lot
@thomasedwardking7286
@thomasedwardking7286 Жыл бұрын
To give so much knowledge to create a playable game in a shade over 4 minutes is just unbelievable. Sir, you just won yourself a follower 🤩
@Flommyplays
@Flommyplays 11 ай бұрын
Same over here
@katsuvr
@katsuvr 8 ай бұрын
How can i make it so instead of flipping the character around it flips the Shooting Point and makes it fires in the other direction, when i flip my controls get mixed up
@RatSentinel
@RatSentinel Жыл бұрын
great tutorial, definitely deserves a sub
@RootGames
@RootGames Жыл бұрын
Much appreciated!
@aryamukasyaf146
@aryamukasyaf146 3 ай бұрын
Thank u for the great insight
@saylasgrivz
@saylasgrivz 8 ай бұрын
thanks
@smevegaming590
@smevegaming590 9 ай бұрын
im having some trouble with anything from the pack even coming up, i might just be stupid but it would be great if you could help me with that!. anyway i love all of your videos (:
@im_2_tugud
@im_2_tugud 10 ай бұрын
What's in the 1st to 10th lines of enemy.cs ?
@asaf333steinberg9
@asaf333steinberg9 Жыл бұрын
1:07 whene i come back to the unity it say "Method must have a return type"" I did evry thing that you did and try every thing. plz help I am in a geme jam and i need to fix it fast
@Amigo-oh2vv
@Amigo-oh2vv Жыл бұрын
Thanks for help But how to make it the longer you press the shooting button the more dammage you deal
@bear5536
@bear5536 7 ай бұрын
How would you make this continuously fire when holding down the shoot keybind.
@RootGames
@RootGames 7 ай бұрын
You need a timer and use Keyboard.current.spaceKey.isPressed
@coreysonofander
@coreysonofander 2 жыл бұрын
What would be a good way to add a delay between shots?
@RootGames
@RootGames 2 жыл бұрын
Create a timer. For example: float timer = 0; float shootDelay = 0.2f; void Update() { if (Keyboard.current.spaceKey.wasPressedThisFrame && Time.time>=timer) { Instantiate(bulletPrefab, shootingPoint.position, transform.rotation); timer = Time.time + shootDelay; } } You can create other types of timers, this is just one example.
@coreysonofander
@coreysonofander 2 жыл бұрын
@@RootGames Got it. Works great! Thank you.
@kartikbhagwat7872
@kartikbhagwat7872 8 ай бұрын
How did you created enemy prefab and spawner? I'm Confused :(
@Games_Seeker
@Games_Seeker 3 ай бұрын
have u got it ?
@ZSkilled
@ZSkilled 11 ай бұрын
What about the Spawner script?
@rec.official
@rec.official 4 ай бұрын
Really cool one 👍
@RootGames
@RootGames 4 ай бұрын
Thanks 😉
@easyminecrafttutorial809
@easyminecrafttutorial809 2 жыл бұрын
root games would you make about double jump or enemy that shoots bullet pls
@RootGames
@RootGames 2 жыл бұрын
The double jump is covered in my Udemy course. I can give you an idea of how to make enemies shoot but there are so many types of enemies. The principle is the same, instantiate the bullet prefab from the enemy shooting point. You can do it with a timer or when the player enters a certain area, then start shooting. Thanks for subscribing :)
@killdeer
@killdeer 6 ай бұрын
Thank you
@RootGames
@RootGames 6 ай бұрын
No problem 😉
@bobbytwobrains
@bobbytwobrains Жыл бұрын
hello is there a way you can just teach me the enemy and killing the enemy tutorial and if you already have one can you please tell me which one? because when I try get the enemy and damage it just gives me errors
@RootGames
@RootGames Жыл бұрын
Seems like you also need to learn the basics of C#. Try my course on Udemy/Skillshare. You will learn C# from scratch and there is also a section about enemies.
@obadanaser5144
@obadanaser5144 9 ай бұрын
i need a full screbt in document file plz :)
@ipinjirjat8238
@ipinjirjat8238 Жыл бұрын
Can you make a clone of the bullet removed when it passes through the camera?
@RootGames
@RootGames Жыл бұрын
To destroy bullets when they go off the screen use OnBecameInvisible and Destroy functions.
@epikwaffles1965
@epikwaffles1965 Жыл бұрын
When I rotate, the shooting point doesn't move with my player, how do I fix this? (I also connected it to the player script
@RootGames
@RootGames Жыл бұрын
It needs to be a child object of the player.
@miftahussyafi
@miftahussyafi 5 ай бұрын
How to enemy get a damage?
@sonofforehead
@sonofforehead Жыл бұрын
At 0:45, how would I make it instead shoot when clicking the mouse?
@RootGames
@RootGames Жыл бұрын
Depending on what input system you are using, old or new. If you want to learn more about the new input system and C# in general, try my course on Udemy/Skillshare.
@krazykase3419
@krazykase3419 Жыл бұрын
is there a way i can shoot in the direction with scaling the player to -1 and 1
@RootGames
@RootGames Жыл бұрын
Yes, you need to have a variable that will store the direction of the player, for example: 1 when he is facing right, -1 when he is facing left, then when you instantiate your bullet prefabs, pass that variable to them and multiply the speed with it, the bullets should fly to the right and left depending on the direction variable.
@munroy529
@munroy529 4 ай бұрын
@@RootGames how to can store the veriable for direction of the player if the bullet is in a different script?
@RootGames
@RootGames 4 ай бұрын
@@munroy529 When you instantiate the bullet, use getcomponent for the script in which you store directions. Then pass it to the bullet in the "Start"
@Games_Seeker
@Games_Seeker 3 ай бұрын
can u explain the practical system that u made in the video ?@@RootGames
@juliapaulewicz1471
@juliapaulewicz1471 3 ай бұрын
Hi, I copied your code for the bullet but it comes up with lots of errors :(. I was wondering if it's maybe, because I'm using the 2022.3.11 version of unity?
@RootGames
@RootGames 3 ай бұрын
No, it’s not.
@juliapaulewicz1471
@juliapaulewicz1471 3 ай бұрын
This is the code that I have for bullet and it keeps coming back with 10 errors :( Some of them say things like "The modifier 'private' is not valid for this item" or "Type or namespace definition, or end-of-file expected". I'm pretty sure I followed the tutorial and copied everything correctly. using System.Collections; using System.Collections.Generic; using UnityEngine; public class Bullet : MonoBehaviour { public float speed; private Rigidbody2D rb; void Start() { rb = GetComponent(); rb.velocity = transform.right * speed; } } private void OnTrigger2D(Collider2D collision) { Enemy enemy != null) { enemy.TakeDamage(20); } Destroy(gameObject); } }@@RootGames
@turtle11t
@turtle11t Жыл бұрын
Hi, Shooting Point (and bullets) doesn't flip with my player. How do I correct that?
@RootGames
@RootGames Жыл бұрын
Shooting point needs to be a child object of the player. Then use rotation as mentioned in the video and it must work.
@turtle11t
@turtle11t Жыл бұрын
Problem is I'm using a different player sprite and script to yours and the rotation code will mess up my sprite
@turtle11t
@turtle11t Жыл бұрын
Also the bullets only fire right.
@Mistacle
@Mistacle Жыл бұрын
does not work says redParticles does not work in Enemyscript
@Ryu-ky5vt
@Ryu-ky5vt 8 ай бұрын
Thank you very much bro subbed immediately
@RootGames
@RootGames 8 ай бұрын
Thanks! 😀
@shantanuudasi
@shantanuudasi Жыл бұрын
Is this the same game you taught in the course?
@RootGames
@RootGames Жыл бұрын
No, if you click on the Udemy link, you can watch a preview of the course.
@nguyentheanhk16_hl3
@nguyentheanhk16_hl3 Жыл бұрын
can u tell more detail about spawner
@4ndrito
@4ndrito 16 күн бұрын
use instantiate along with a empty game object to declare where to spawn your prefab
@SansNova.
@SansNova. 2 ай бұрын
3:20 , please give me the full script , like i need it rn , please
@munroy529
@munroy529 4 ай бұрын
i cretead a bullet but it doesnt flip side, its always shooting to the right side
@RootGames
@RootGames 4 ай бұрын
Maybe you are flipping the player using scale and not rotation.
@MillionaireExample
@MillionaireExample 3 ай бұрын
My bullets jus fly in to one direction😂
@kapcapkapcap6104
@kapcapkapcap6104 4 ай бұрын
3:33
@kuleCristo
@kuleCristo 11 ай бұрын
I love you i think
@GameWithMe469
@GameWithMe469 Жыл бұрын
my projectile is not moving and i don't know why
@outsidehockey1532
@outsidehockey1532 Жыл бұрын
I had the same problem ???
@GameWithMe469
@GameWithMe469 Жыл бұрын
I can spawn the Bullet in but not get it to move
@RootGames
@RootGames Жыл бұрын
Spawn the bullet and then pause the game. Inspect your spawned bullet. It has to have the Bullet script and Rigidbody2D component. Also check that the speed variable is not 0.
@indiafreedomgaming3898
@indiafreedomgaming3898 9 ай бұрын
Where is the redPartical File. What is written there.
@RootGames
@RootGames 9 ай бұрын
Red Particle is a particle system prefab.
@Cont1nue0
@Cont1nue0 11 ай бұрын
better write [SerializeField] private
@svardleo5275
@svardleo5275 Жыл бұрын
Using the new Input system fucks with my other scripts
@RootGames
@RootGames Жыл бұрын
You can do the same thing with the old system, but consider shifting to the new. The old one is ditched by Unity, the future is the new system.
@abbbab
@abbbab Жыл бұрын
real
@MilanToabs
@MilanToabs Ай бұрын
It sadly breaks my entire character i start rotating infinitly
@4ndrito
@4ndrito 16 күн бұрын
can i see your movement script?
@SirHotDogManTheFirst
@SirHotDogManTheFirst Жыл бұрын
My bullets fell straight to the ground
@RootGames
@RootGames Жыл бұрын
Make sure you set gravity to 0.
@yazanjordan3103
@yazanjordan3103 Жыл бұрын
its hard to follow you can u slow down a bit
@problemforyou
@problemforyou Жыл бұрын
pause the video
@crshorts-6286
@crshorts-6286 Жыл бұрын
Im so bad at developing that even this does not work for me
@RootGames
@RootGames Жыл бұрын
Don't give up! 😉
@indiafreedomgaming3898
@indiafreedomgaming3898 9 ай бұрын
Upload The Code.
@RootGames
@RootGames 9 ай бұрын
Sorry, I don't have it anymore, but you can see everything in the tutorial. The only thing you need to create is your Particle System prefab.
@nandakishorsd6731
@nandakishorsd6731 2 жыл бұрын
plzz your discord server
@RootGames
@RootGames 2 жыл бұрын
Hey Nanda, sorry but the discord server is exclusive and available only for people who enrolled in my courses. You can find them on Udemy or Skillshare 🙂
@nandakishorsd6731
@nandakishorsd6731 2 жыл бұрын
@@RootGames thats really sad :(
@RootGames
@RootGames 2 жыл бұрын
​@@nandakishorsd6731 Don't be sad. Black Friday is coming and courses will be at really affordable prices, even now there are coupons in the description🙂
@nandakishorsd6731
@nandakishorsd6731 2 жыл бұрын
@@RootGames oh ok then I will be waiting for that! really really waiting for your course to get in my hand XD
Unity 2D: Grab Objects
3:35
Root Games
Рет қаралды 17 М.
Unity 2D Aim and Shoot at mouse position Tutorial
14:39
MoreBBlakeyyy
Рет қаралды 68 М.
Угадайте концовку😂
00:11
Poopigirl
Рет қаралды 4 МЛН
АВДА КЕДАВРАААААА😂
00:11
Romanov BY
Рет қаралды 6 МЛН
2D Shooting in Unity (Tutorial)
21:12
Brackeys
Рет қаралды 1,2 МЛН
Creating SMART enemies from scratch! | Devlog
5:40
Challacade
Рет қаралды 218 М.
The BEST ART TOOL You Didn't Know YOU NEED (and how to use it)
16:53
Simple Shooting | 2D | Bullets | Unity Game Engine
3:07
Unity3D School
Рет қаралды 25 М.
3 Ways to Shoot Projectiles in Unity!
23:07
Code Monkey
Рет қаралды 236 М.
Building a HIGH SPEED Rocket Plane
17:53
ProjectAir
Рет қаралды 362 М.
I re-coded Minecraft, purely for MAXIMUM FPS (World Record)
11:26
Make a FIRST PERSON SHOOTER in 10 MINUTES - Unity Tutorial
12:12
TOP DOWN MOVEMENT in Unity!
22:30
Brackeys
Рет қаралды 1,2 МЛН