Тёмный

2D Shooting | Unity Tutorial (Two Types of Projectiles!) 

Sasquatch B Studios
Подписаться 40 тыс.
Просмотров 11 тыс.
50% 1

Show your Support & Get Exclusive Benefits on Patreon (Including Access to this project's Source Files + Code) - / sasquatchbgames
Join our Discord Community! - / discord
By the end of this 2D Unity tutorial we'll have our little character shooting and damaging enemies with our ranged combat system.
I'll show you how to aim your gun towards the mouse cursor (using the new Input System,) how to rotate the gun after a certain degrees threshold, and how to rotate your bullets when they are spawned in (as well as how to rotate them towards your velocity direction!)
To make this more fun, I'll show you an easy way to setup TWO kinds of projectiles that you can shoot.
I cover a lot here, so we're going to go through this 2D shooting tutorial fast!
Link to Download the FREE 2D Asset Pack seen in this tutorial:
veilofmaia.com/tutorial-asset...
---
In need of some Unity Assets? Using our affiliate link is a great way to support us. It's free, and we get a small cut that helps keep us up and running: assetstore.unity.com?aid=1100lwgBQ
---
Credits-----------------------------------------------------
Unity Vector2.normalized Documentation Pic:
docs.unity3d.com/ScriptRefere...
Contents of This Video: ------------------------------------------
00:00 - Intro + Scene Explanation
00:42 - Rotating Gun Towards Mouse
03:58 - Flipping the Gun When You Aim Backwards
06:53 - Instantiating Bullets that Face the Shot Direction
10:27 - Get Bullets to Move in Shot Direction
12:21 - Handling Bullet Destruction
14:53 - Adding a Second Bullet Type to BulletBehavior
19:15 - Rotate Bullets' Facing Direction Based on Velocity
19:51 - Applying Damage to ANY Damageable Object
Who We Are-------------------------------------
If you're new to our channel, we're Brandon & Nikki from Sasquatch B Studios. We sold our house to start our game studio, and work full time on building our business and making our game, Veil of Maia.
Wishlist our Games:
Wishlist Samurado on Steam! - store.steampowered.com/app/23...
Wishlist Veil of Maia! - store.steampowered.com/app/19...
Don't forget to Subscribe for NEW game dev videos every Monday & Thursday!
Follow us on Twitter for regular updates!
/ sasquatchbgames
#unitytutorial #unity2d #unity3d

Игры

Опубликовано:

 

30 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 29   
@Notreal76
@Notreal76 Год назад
Clear and comprehensible. Thank you!
@Ramesss
@Ramesss 4 месяца назад
AMAZING !!!! You saved me for my Second Semester project love you
@mansimoe319
@mansimoe319 4 месяца назад
Genuinely insane
@meowl9329
@meowl9329 Год назад
I love these! Would want to see you cover the system part, like game saving, data structure, handling multiple scenes etc.
@sasquatchbgames
@sasquatchbgames Год назад
thanks! Already had two of those on my future list ;)
@chadmoberly7044
@chadmoberly7044 Год назад
Super helpful!
@apollodavis4090
@apollodavis4090 Год назад
Love your devlogs
@sasquatchbgames
@sasquatchbgames Год назад
Thank you!
@capilover1023
@capilover1023 6 месяцев назад
Have you thought about doing a tutorial on the weapon system? Switching between weapons, maybe adding UI icons, etc.
@midniteoilsoftware
@midniteoilsoftware Год назад
A much simpler solution for handling collisions is to just use the collision matrix in the physics settings. That negates the need for any code.
@midniteoilsoftware
@midniteoilsoftware Год назад
A cool follow-up video would be how to use ScriptableObjects for bullet types.
@sasquatchbgames
@sasquatchbgames Год назад
I love scriptableObjects :D
@midniteoilsoftware
@midniteoilsoftware Год назад
2 time-saving tips: edit the script template so it doesn’t include all the boiler plate code you always remove anyway and there is a setting under preferences to create objects at origin so you don’t need to reset the transform every time you create a new GameObject.
@sasquatchbgames
@sasquatchbgames Год назад
those are 2 things I've been procrastinating lol. Thanks for the tip, I'm going to have to do both of those
@nickrhyswarren
@nickrhyswarren Год назад
Hi there! Great tutorial as always. I've implemented this after doing the Hollowknight style camera tutorial which took a bit of figuring out as it effected the rotation of the gun (if anyone wants help just ask). The multiple cameras caused problems. I am trying to modify this to suit my game. I have an ability system with upgrades and have tried to add a multishot upgrade, but its a bit buggy at the moment, it shoots three bullets at once in an arc but the extra two just shoot sideways :( I used Quaternion.Euler in the Instanciation of the bullet to be able to change its y axis rotation but that hasn't worked. I'm also struggling with trying to flip the character when rotating the gun past 90/-90 degrees like the gun. The player movement and jumping is turned off and the attack ability is turned on as well as the gun when holding down the attack button. The player can flip when aiming past 90/-90 degrees like the gun however, when exiting the attack (Releasing attack button), if the player is facing left it messes up the flip function of the player so that he is facing the wrong way when moving. I'm sure ill figure it out, but if anyone has a good solution for flipping the character I'd appreciate the help!
@capilover1023
@capilover1023 6 месяцев назад
Please update the lesson for perspective camera! It seems to mess up your code
@Teles0704
@Teles0704 3 месяца назад
my bullet is being destroyed when it spanws, what can i do?
@CyberAngel67
@CyberAngel67 Год назад
I would argue that as you are setting the transform right to the velocity it doesn't need to be done inside a FixedUpdate.
@sasquatchbgames
@sasquatchbgames Год назад
just gave it a shot in Update, and it produced weird janky movement. Definitely works best in FixedUpdate
@CyberAngel67
@CyberAngel67 Год назад
@@sasquatchbgames Then you did it wrong
@suzyeon4222
@suzyeon4222 4 месяца назад
when I rotate, the gun rotates in the wrong direction. Please help
@suzyeon4222
@suzyeon4222 4 месяца назад
i mean the sprite rotates in the right direction but when im facing left side it's the opposite direction. sorry my English is bad
@lancerdev2391
@lancerdev2391 Месяц назад
@@suzyeon4222 Hi, I had the same problem and came up with a simple solution. Instead of flipping my player, I flip the sprite. Next, in my gun script, i modified this : float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; Vector3 localScale = new Vector3(1f, 1f, 1f); Vector3 localPos = gun.transform.localPosition; if(angle > 90 || angle < -90) { localScale.y = -1f; localPos.x = -1f; } else { localScale.x = 1f; localPos.x = 1f; } gun.transform.localScale = localScale; gun.transform.localPosition = localPos; If flips the gun depending on the facing direction of the sprite of the player. Hope this helps !
@Coco-gg5vp
@Coco-gg5vp Год назад
First
@midniteoilsoftware
@midniteoilsoftware Год назад
Nobody beats Coco!
@y0_0go
@y0_0go Год назад
At 5:45, you could have just used gun.transform.localEulerAngles.z instead of rotation. Correct me if I am wrong. In the end, you use interface and grab a reference to that instead of grabbing enemy script. The reason you say is because there are other objects that get destroyed by bullet. But, you wouldn't add enemy script on other objects. Right ?. So only enemy gets to have enemy script and you don't need an interface there. Really loved your video
@midniteoilsoftware
@midniteoilsoftware Год назад
A more concise syntax is if (collision.gameObject.TryGetComponent(out var damageable)) …
@midniteoilsoftware
@midniteoilsoftware Год назад
Cheaper than a null comparison
@sasquatchbgames
@sasquatchbgames Год назад
Thanks for the tip! I'm going to try that out
Далее
How to Start Gamedev in 2024
10:28
Просмотров 458 тыс.
How to Make a Good 2D Camera
11:38
Просмотров 393 тыс.
10 Unity Tips You (Probably) Didn't Know About
6:47
Просмотров 37 тыс.
I Paid Fiverr Game Developers to Make the Same Game
10:25
Developing my FIRST Game
7:46
Просмотров 14 тыс.
Watch This BEFORE making Your First Indie Game!
7:23
Просмотров 221 тыс.
How To Escape Tutorial Hell
10:07
Просмотров 7 тыс.
I Made the Same Game in 8 Engines
12:34
Просмотров 4 млн
The LIES You've Been Told About Gamedev
9:41
Просмотров 10 тыс.