Unity 2D Platformer for Complete Beginners - #10 ENEMIES

preview_player
Показать описание
In this episode we'll finally create melee enemies and ranged enemies. Then we'll add a simple patrol behavior to our enemies.

Consider supporting the channel on Patreon:

#pandemonium​ #unity2dplatformer​ #unitybeginner​

Tags: unity 2d platformer for complete beginners,unity 2d platformer,pandemonium games,platformer for complete beginners,unity 2d enemy,unity health system,unity enemy,Unity 2D Platformer for Complete Beginners - #10 ENEMIES,unity 2d enemies,unity melee enemy,unity ranged enemy,unity 2d platformer episode 10,unity patrol ai,unity 2d ai patrol,unity simple patrol,unity simple patrol behavior,unity damage enemies,unity melee enemy ai,unity ranged enemy ai

0:00​ Intro
0:15 Enemy sprites & Animations
9:06 Melee Enemy AI
20:15 Patrolling
31:52 Damaging Enemies
33:50 Ranged Enemy AI
45:10 Disabling Enemies
48:50 Contact Damage from Enemies
49:37 Firetrap Fix
51:36 Outro & Patreon Shoutout
Рекомендации по теме
Комментарии
Автор


For everyone who's getting UnassignedReferenceException when your fireballs hit something change this part of the code:
to this:
The ? will check if the object has a Health component before trying to damage it.

PandemoniumGameDev
Автор

Probably one of the best unity tutorials creator, you dont just make us copy the code( yes doing this we would create a game, but we don't learn nothing about how to make a game by ourself), but you explain well how the code we just typed works! Sad to see the channel really underrated :(

mrsworder
Автор

I've been looking for reliable and easy to understand Unity tutorials and I hadn't found one... Until now. Your explanations are wonderfully constructed and I actually feel like I am learning. It's quite sad to see how little subscribers you have, but at least I can contribute by adding one more! Thank you for these videos and I hope you have an amazing 2022!

tapthelvete
Автор

18:42 little optimization quirk

Putting in "if(hit.collider != null)" inside the "PlayerInSight()" method to see if it needs to get the health component of the player means it's doing this check every single frame. Plus, it re-assigns "playerHealth" with the same value every frame the player is in range. But the method already returns the result of "hit.collider != null" at the end. The DamagePlayer() method already checks "if(PlayerInSight())" to execute "TakeDamage()", so it's basically doing the same check twice.

You can just declare the "Raycasthit2D hit" variable as private outside of the method, which means DamagePlayer() will have access to it when it's called. You end up not needing the "playerHealth" variable. So it can just be:

private void DamagePlayer()
{
if(PlayerInSight())

}

The only way PlayerInSight() will return true (and therefore run the next line) is if the "hit" variable currently contains the player object it has collided with in the check. Had no issues trying it this way. Saved a single glorious check per frame. Mom would be proud.

mapkocc
Автор

Greatest Tutorial With All Details Ever Seen Here in my 1.5 year of learning started from WebDev to Get Understanding of Programing then Android App Development and finally half year ago started unity and that is were i want to stop Shout Out To this Man He is Incredible

siyovushdodojanov
Автор

Another good video. I got everything to work, and was able to solve any issues I had.

I would like to share that the last issue I had was that my RangedEnemy Firepoint was not changing direction with the RangedEnemy's direction. I found out that the FireballHolder(the empty object that holds the Projectiles) had to have a similar setup as the Player in that it cannot be a child of the RangedEnemy.

waltersattazahn
Автор

Wow... Underrated... Code actually works unlike other codes.

maxy
Автор

Ive been waiting for so long, so happy the new one is out!

RMCMiner
Автор

Thank you so much I have been stuck on this for days. Really helped thanks.

PokimBarran
Автор

i will not give up and finish this series !!!

balab
Автор

Finally! Thanks so much! Your tutorials are really helpful and well organized.

cmemfrx
Автор

Great series as always! Quick thing I found at the end of this tut is the EnemyPatrol object can be very specific about what variables are active in it. You have to plug these variables in when we first made it (I think they are "Enemy: Enemy" and "Enemy:Anim". If you add an enemy to the hiarchy that also has EnemyPatrol object, you must plug those variables back in or your enemy won't move/attack/idle. Maybe I just missed something, or maybe there's a workaround, but it's not THAT bad. Just good to keep in mind

scorpiusjones
Автор

If you want a different enemy sprite that looks a bit different there is also ninja sprite sheet on the unity asset store by the same creator as the knight one.

PianoGreenGaming
Автор

I still have a problem when melee enemy patroling the points he doesn't stop to hit me. He goes to the end of the edge and only than makes a hit///

Majitsu_san
Автор

Thank you so much for the wonderful unity 2D platformer series. I enjoy creating the games along with you. Usha

ushas
Автор

I dont know why but i have the code completely same but my RaycastHit2D hit does not trigger when player is inside the red box

prochysolaire
Автор

thANKS NOW I KNOW HOW TO MAKE A TIMER sorry for capslock im to lazy to change them

patrickkusmajadi
Автор

I resolved an issue that bugged me for a long time: whenever the enemy changed direction, all enemy fireballs already in flight suddenly appeared on the other side of the screen, because the Enemy fireball holder changed direction along with the enemy. I couldn't figure out why this is not happening in the tutorial, and why behaviour was different for me. I finally fixed it by disabling the EnemyFireballHolder script (which follows the direction of the enemy) and instead implementing the same logic that is applied to the player fireballs (set direction in the PlayerAttack and Projectile scripts) in the RangedEnemy and EnemyProjectile scripts. Now everything works as expected, maybe this helps others with the same issue.

malwida
Автор

MissingReferenceException: The object of type 'Animator' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.

PavanKumar-hsqz
Автор

This is the best channel in the world. I learned many things from you and applied them and became good at making games. Thank you.

anastarek