Thanks for everyone for the patience, this one was a pain to record, I managed to mess up the video a couple times and had to redo it. Hope everything is clear and let me know if you need help, also check the GitHub project if you need the code: github.com/nickbota/Unity-Platformer-Episode-10 For everyone who's getting UnassignedReferenceException when your fireballs hit something change this part of the code: collision.GetComponent().TakeDamage(damage); to this: collision.GetComponent()?.TakeDamage(damage); The ? will check if the object has a Health component before trying to damage it. ● Support the channel on Patreon or UA-cam: www.patreon.com/pandemonium_games ua-cam.com/channels/pkMj5b5kl2_YApDvgUCVQQ.htmljoin ● Subscribe to the Weekly Pandemonium Newsletter: www.pandemonium-games.com/#:~:text=About%20Me-,Weekly%20Pandemonium,-Subscribe%20to%20our
Epic video! idk why the channel is underrated I guess no one wants to become and Albert Einstein like you!(im not smart) Ahem.. Btw the EnemyFireball is not visible when he the enemy shoots but the invisible fireball still hits the player the sorting layer on the fireballs is set to Foregrounds so idk the problem Please Help dude!
Idk if I'm too late; but you can click the + icon in the MeleeEnemy/RangedEnemy script, and select the EnemyPatrol game Obejct in it. It would load up the script in it, and then it would also disable the EnemyPatrol script@@purejaguare
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 :(
Yo bro can you help me with the DamagePlayer() Event in Melee Attack in the script it is saying it is unused and in the unity editor its saying its not supported so how do you fix it? pls help Epic Tutorial btw Love it!@@PandemoniumGameDev
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!
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
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
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.
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.
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.
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()) hit.transform.GetComponent().TakeDamage(damage); } 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.
If someone's fire ball is shooting without any cooldown, go to animation, and check the transition from ranged attack back to idle and make sure there isn't a trigger(ranged attack) there
Another dumb question, my ranged enemy works perfectly. Except that when he is patrolling he is moving backwards haha. Like he moves right while facing left. He hits the right edge and turns, then he faces right and moves left. I'm using a different sprite but I'm sure it's something I'm overlooking. Thanks.
I'm not a game engine guy i prefer coding everything , but i think the problem can be resolved by change flip depending on your sprite , if it is face right by default in left controller set it to true then set it back to false in right controller ,else do the opposite. Here's an example : ua-cam.com/video/XIEtt4GH_Mo/v-deo.html
for some reason the animation isnt triggering ..i dont know why..the enemy is just standing on idle....i did the code like you did but the enemy wont attack the player
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.
Would it not make more sense to make a base Enemy class and then have RangedEnemy and MeleeEnemy inherit from it to prevent copy and pasting your code?
I think you are correct. I know this is a year old, but its awesome when people who are learning think of optimization. Personally, I am glad he did not do it because it allows people learning room to grow.
i want to congratulate you for you r good tutorial ,but i have a little issue : enemy fireballs dont go into the right direction , and even by doing what you have done at minute 41:00 it didn't worked and i don't know how to fix , do you know something to help me?
for some reason i get the red box but when the player walks into the range of the enemy the attack animation does not trigger and the player doesnt even get damaged. and i think the root of the problem is the raycast is not detecting the player is there as the animation when the player is in sight to attack is never called.
no idea if this is still relevant, but I had the same problem and its probably not the best way to solve it but I simply put the distance value (5th one) > 0 and that triggered the animation for me RaycastHit2D hit = Physics2D.BoxCast(boxColl.bounds.center + transform.right * range * transform.localScale.x * colliderDistance, new Vector3(boxColl.bounds.size.x * range, boxColl.bounds.size.y, boxColl.bounds.size.z), 0, Vector2.left, *0.2f* , playerLayer);
Thank you so much for all these videos! Idk where I’d be without it!! Do you think you can show us how to make our character go between scenes, like going between levels?
so my problem is with the patrol and attack of the ranged enemy it moon walks left and right (faces the wrong direction its going) and the range doesn't flip with the enemy, i've downloaded the finished copy of this episode to make sure his is working which it is, so i copy and pasted all the code related the the ranged enemy into my scripts so the codes are the same and cross referenced everything in the inspector so all the positions, scales and script inputs are the same but it still broke ...help!
i fixed my problem just by deleting the Ranged Enemy from the Enemy Patrols "enemy" and "enemy animator" functions then putting them back into the Enemy Patrol fixed my problem
the EnemyFireball is not visible when he the enemy shoots but the invisible fireball still hits the player the Sorting layer on the fireballs is set to Foregrounds so idk the problem Please Help someone!
14:54 Is it neccesarry to take existing BoxCollider2D and using its properties make damage area. Is it possible to add second BoxCollider2D component just for that purpose or making damage area? Or would it be less optimized to do so?
Hey, great videos by the way. I just have a question which i cannot find the answer to, at 33:02 I clicked on the MeleeEnemy and opened my Animator, but all the animator parameters just vanished. I can't find them. the parameters are there, just no buttons are showing up. My die, is gone, moving, melee, ranged and hurt are vanished. any suggestions?
Can’t you just put a script on the enemy that stores the starting position and the allow distance from start, and then do calculations in update to get the patrol behavior? Like is there a reason we need 4 objects just for 1 enemy? Genuine question.
My ranged enemy keeps shooting fireballs even when the player is out of sight while he is walking in the opposite direcetion! Any reasons for that? thanks for the videos, great tutorials as usual.
Glad to help! Yes, Unity mostly uses Vector3 since it's a 3D engine, so it needs 3 coordinates for most functions even or 2D games. There are some exceptions where you can just use a Vector2 but it in my opinion it's just easier to use Vector3 in most places
Hello, can you help? Very necessary!! 1. The enemy continues to hit when he is patrolling and when he killed me. 2. When my character is dying, he continues to move, and when I jump, his image appears, what should I do? Perhaps someone knows...
Hi, I followed the instruction at around 5:08 , i did exactly what the video shows step by step but first, it shows : "Transition Idle - Attack in state Idle doesn't have an Exit or any condition , transition will be ignored" after i added the attack condition my enemy always doing the attack anim and not idle state, Anyone know how to fix?
This is absolute awesome. I have just one question. When i create event on end of animation die when i kill enemy he stop using those two scripts but he will not disapeare and because of the script enemy damage can still hurt me.
Not sure if anyone had this issue but when I would press play the MeleeEnemy would disappear. The only way to get it to work was to change the value of "Near" to -10 in the Clipping Planes under "Main Camera" If anyone knows why this was happening to me/ why this solution fixed the issue, the feedback would be greatly appreciated.
If anyone else is having issues detecting player with RaycastHit2D change this part "boxCollider.bounds.size.x * range" to this "boxCollider.bounds.size.x" in the second parameter of the BoxCast function. For example: private bool PlayerInSight() { RaycastHit2D hit = Physics2D.BoxCast(boxCollider.bounds.center + transform.right * offset * transform.localScale.x * colliderDistance, new Vector2(boxCollider.bounds.size.x, boxCollider.bounds.size.y), 0, Vector2.left, 0, playerLayer); Debug.Log(hit.collider); return hit.collider != null; }
Thank you so much for releasing a new tutorial. Been following this series and making my very first platformer! Out of curiosity, why not use the new PlayerInput system for the controls, or the Cinemachine for camera movement?
I have a problem with enemyPatrol. I was follow your video many times but I can't found what's the wrong is. while on patrol to the left, he walks backwards and the scale doesn't turn to minus. Can you help me please?
Hello, in the firetrap episode you said you corrected so that player takes damage when he steps on to the firetrap and sit there idle. But I folled all your corrections. But still player does not receive any damage when he sits on the firetrap continuously without moving! Pl give me some hint to solve this issue.
I have a problem with enemy patrol, when i run it enemy turns right but he doesn't move right like for you in the video. Can anyone help? Edit: My death animation was the issue, it works now
The boxcast/playerinsight function returns true no matter what, even if my player is clearly in the box. I saw that you had IsTrigger activated, but doing so makes my enemy clip through the floor. Really confused, need help!!!
im on the patrol part and for some reason i dont see the enemy when i start the game, unless i disable the animator and than its working good just without the animations of course... any idea what could happen?
friend, I have a problem, I did everything right and if I came out with an enemy, but when I create another and put the scripts into it, it doesn't hurt, it can perform all the animations but it doesn't hurt the player and it doesn't give any errors, what could it be??
First of, I want to say that you have a great tutorial! I have been following ur first until this video for my personal project. Unfortunately, I'm having an issue in Ranged Enemy AI. Specifically in 40:08, I could not get to play in Unity, as I encountered an error message "UnassignedReferenceException: The variable anim of enemyPatrol has not been assigned." I also see that in 39:48-39:50 in your video, which mentions how you do not have the enemyPatrol assigned. I tried following your tutorials and even tried restarting your video to see the issue, but haven't figure out how to solve it yet. What seems to be the problem and how can I solve it?
enemy teleports to location of where i did the animation edit: i had to apply root motion then it works. lmao every time i get a problem that the internet cant fix i post my problem in the comments then after a few minutes i find a fix. but i have another problem where the enemy is staying idle when i go inside the box
Hi. I just have a question which i cannot find the answer to, at 47:33 to 47:43 what to do. did not change RangedEnemyHolder to MeleeEnemy. I did not understand this part 47:33 to 47:43. What did you do?. Please help me
Im having some troubles making it turn, for some reason it does the patrol but its not actually turning when it gets to the other side. I check the code and everything seems ok, melee one works, ranged one doesnt.
I've run into a bug that I can't figure out. So the line of sight was working properly with my melee enemy. However in working on the ranged enemy his line of sight is no longer flipping with him. So it starts off fine in the correct direction he's facing. Though the enemy walks backwards rather than forwards. Then when he gets to the patrol edge he turns around but the field of vision gizmo stays the same direction. so if the player is behind him, it triggers the enemy to fire a fireball. However the fireball still fires forward away from the enemy but is triggered from behind the enemy as his field of vision doesn't change. He also continues to walk backwards if you're out of his "line of sight". I've checked all my scripts to yours but they look fine to me. No errors are compiling in Unity. So I have absolutely no ideas on how to fix this issue. I also tried changing his direction of both the ranged enemy and the ranged enemy holder but this only seems to flip the sprite so he may then walk in the correct direction but his field of view still doesn't change. Same issue if I change just one of the objects direction he starts walking the right direction but his field of view stays behind him.
Well update after playing around with the x position on the ranged enemy and Ranged enemy holder I fixed the walking backwards issue. The enemy now flips but I still cant get enemy field of vision box collider/gizmo to flip. So the enemy walks forwards and heading one direction his line of sight is in front of him but the other direction the box is behind him. I know we wrote code to make the box flip too, but again I've checked all my code a few times now and I'm not seeing any errors to fix this issue.
41:28 the EnemyFireballHolder script causes the enemy fireballs to shoot at the enemy when it is facing the left. When it faces right, the fireballs shoot to the right. [EDIT] I solved this. Answer is in the reply.
I figured out my problem. I had incorrectly set the game object hierarchy and Firepoint was not a child of RangedEnemy. If you are following along, make sure you're checking your game object Child / Parent structures. I was so tired I didn't realize I had overlooked where it was sitting. Interesting how something so small can have such a large effect.
Hey, I didn't wanted the range enemy so I didn't change the way how the script Health works. Will this cause problems for me in the next tutorials? (In my case just the audio tutorial and the chekpoints & respawn tutorials).
Not sure if someone still can answer my question but I got an issue when my player gets hit The player is out of the range of the enemy but still get damage. How to fix that issue? I am using a linecast to check if the player is in range
@PandemoniumGameDev In the unity console it is displaying that the "animator for the melee enemy has been destroyed but you are still trying to access it" Can you suggest a solution to this btw love your tutorials
Pandemonium, I have a problem with my game. I've typed the code like yours, but the problem in second 23:16 still occurs. Do you have any idea what should I repair?
Hi, I had a problem with scaling my sprites. Knight on the video is on transform scale: 1, but my enemies are on scale 0.2 when I want the same height as my dragonknight. Yeah I could resize all my enemies to correct resolution size, but I didnt want to do that. So, the problem: When I resize my enemies - then Gizmos and RaycastHit wasnt same height as my box collider - it was actualy two times bigger. Fixing this bug was quite easy (But for my dumb brain it was like 40 minutes strugling): You need to add to your new Vector3 transform.localScaleY. So the code for Gizmos is: Gizmos.DrawWireCube(boxCollider.bounds.center + transform.right * range * transform.localScale.x * colliderDistance, new Vector3(boxCollider.bounds.size.x * range, boxCollider.size.y* transform.localScale.y, boxCollider.bounds.size.z)); And for RayCastHid2D: RaycastHit2D hit = Physics2D.BoxCast(boxCollider.bounds.center + transform.right * range * transform.localScale.x * colliderDistance, new Vector3(boxCollider.bounds.size.x * range, boxCollider.size.y * transform.localScale.y, boxCollider.bounds.size.z), 0, Vector2.left, 0, playerLayer); Sorry if this is stupid or apparent, but I havent seen anyone mention this here. Also sry for my English, I am just dumb :D
I got everything in this video to work with the exception of the collision with enemies causing damage. My enemies are being treated like solid objects, so my player is blocked by their hitboxes and is able to stand on top of them. Any suggestions as to what can be causing this?
hello i have problem about damage enemy with fireball, fireball not damage enemy but enemy stop moving when i shoot 3 fireball ( i copy/paste you code but not working )
I'm having a problem with my arrowtrap ever since I changed the enemy projectile script every time it hits the player or the wall it stays frozen there and keeps shooting. I think because it's not disabling when it hits anything. Any opinions?
Hi, thanks for the tutorials, very helpful. I'm hoping you can help me with something? My melee enemy is patrolling the space I assigned but he is walking backwards? Any ideas?
Solved the problem when enemy patrol , it's not damaging, put if (enemyPatrol != null) { enemyPatrol.enabled = !PlayerInSight(); } instead of (enemyPatrol != null) enemyPatrol.enabled = !PlayerInSight(); Hope it will help someone, because it helped me.
I am trying to figure out how to implement the enemy damage in my code which I have made a few tweaks to to not include player projectiles. I want to handle the damage the same way but just on the mouse click. How would I incorporate that?
Hey man, sorry I'm a little late to the party but I'm having some issues with the enemy patrolling script. I have set up everything they way you have it in the video, assigned all the parameters, however, when I run the game in unity the enemy is teleported to the right edge point, has turned left and is performing the walking animation but not moving. Any ideas you can run by me?
I'm making a basic box game and i just wanted to know wether the enemy animation is neccessary for taking damage (wich it probably isn't(i dont really want to make animations because boxes dont usually do anything)) because every time i walk up to the enemy nothing happens. Even when i created an object that should damage the player nothing happened. Also the enemy is invisible even tho it has a sprite renderer.
Sorry, I followed your course. When I did the 41:48 part, I wanted the enemy in my range to be able to shoot arrows, but after he detected the player, although he shot the arrow, it disappeared instantly. Why is this? By the way, I didn't animate my arrows, could it be related to the animation?
plz, help me, my RangedEnemy can't movement with patrol, when I input RangedEnemyHolder to Patrol he can move around but collider box is not change position.......sorry, my English so BAD =(((((((
Yeah, you have a couple options. 1. Change the entire character sprite or 2. Divide the character into a couple images: hair, chest, arms etc and then change the sprite or color on each individual element like Goku's hair turning yellow.
'FireBall (8)' AnimationEvent 'Deactivate' on animation 'Fireball_explode' has no receiver! Are you missing a component? does anyone else get this please i need help
Nice tutorial! I finally have my ranged enemy patroling perfectly in the scene but when I try to create a prefab of it to use it in another scene it just don't work for some uknown reason. It keeps patroling but he doesn't attack the player and I have all tags displayed correctly. I thought it was a bug but it does the same in older versions of unity. I just don't find how to solve it!
It could possibly be because the Ranged Enemy does't have any movement logic attached to it alone, that's in the Enemy Patrol script. It seems like anytime I remove/add a enemy to the scene, I need to plug the info into the Enemy Patrol prefab in the hiarchy to make the enemy patrol
Hello. I have a question. I have a GroundSpawner and EnemiesSpawner and my enemy with isTrigger Box Collider 2D just keps falling down through the platform. How can I solve this problem? Can do it only via coding or there's another solution?
hey, was just wondering that is there any way to make the player damage the enemy through melee attacks.i followed through all the scripts but i did not wanted to add a projectile attack system but now im stuck as i dont know how to damage the enemies through melee attack
Thanks for everyone for the patience, this one was a pain to record, I managed to mess up the video a couple times and had to redo it. Hope everything is clear and let me know if you need help, also check the GitHub project if you need the code: github.com/nickbota/Unity-Platformer-Episode-10
For everyone who's getting UnassignedReferenceException when your fireballs hit something change this part of the code:
collision.GetComponent().TakeDamage(damage); to this: collision.GetComponent()?.TakeDamage(damage);
The ? will check if the object has a Health component before trying to damage it.
● Support the channel on Patreon or UA-cam: www.patreon.com/pandemonium_games
ua-cam.com/channels/pkMj5b5kl2_YApDvgUCVQQ.htmljoin
● Subscribe to the Weekly Pandemonium Newsletter: www.pandemonium-games.com/#:~:text=About%20Me-,Weekly%20Pandemonium,-Subscribe%20to%20our
lovely videos, you are an excellent teacher, thanks for helping us.
Hello sir when I hurts my enemy he get die but still moving please sir tell me
Epic video! idk why the channel is underrated I guess no one wants to become and Albert Einstein like you!(im not smart)
Ahem.. Btw the EnemyFireball is not visible when he the enemy shoots but the invisible fireball still hits the player the sorting layer on the fireballs is set to Foregrounds so idk the problem Please Help dude!
I have a problem where the person dies but keeps moving when I move over him.
Idk if I'm too late; but you can click the + icon in the MeleeEnemy/RangedEnemy script, and select the EnemyPatrol game Obejct in it. It would load up the script in it, and then it would also disable the EnemyPatrol script@@purejaguare
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 :(
Really glad to help! Don't worry it's been growing steadily, also I need to be more consistent and put out more stuff
Yo bro can you help me with the DamagePlayer() Event in Melee Attack in the script it is saying it is unused and in the unity editor its saying its not supported so how do you fix it? pls help
Epic Tutorial btw Love it!@@PandemoniumGameDev
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!
Thanks a lot! It's been growing steadily, we'll get there
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
Wow... Underrated... Code actually works unlike other codes.
Ive been waiting for so long, so happy the new one is out!
Thanks a ton for waiting!
Finally! Thanks so much! Your tutorials are really helpful and well organized.
Thank you so much for the wonderful unity 2D platformer series. I enjoy creating the games along with you. Usha
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.
This is the best thing to hear! Thanks a lot and keep getting better 🔥
Thank you so much I have been stuck on this for days. Really helped thanks.
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
Following so far and loving it!
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.
thx you saved me
ur a life saver man
i will not give up and finish this series !!!
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.
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.
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())
hit.transform.GetComponent().TakeDamage(damage);
}
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.
Thanks for uploading. after waiting all this time
Thanks for waiting this long!
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
did u solve it? and if yes, how?
@@sogyshorts5662 Having the same issue as well!
Thank you so much for this course, it is really helpful!
If someone's fire ball is shooting without any cooldown, go to animation, and check the transition from ranged attack back to idle and make sure there isn't a trigger(ranged attack) there
my meleeAttack animation is called 2 times. How to fix it bro ?
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///
Another dumb question, my ranged enemy works perfectly. Except that when he is patrolling he is moving backwards haha. Like he moves right while facing left. He hits the right edge and turns, then he faces right and moves left. I'm using a different sprite but I'm sure it's something I'm overlooking. Thanks.
I'm not a game engine guy i prefer coding everything , but i think the problem can be resolved by change flip depending on your sprite , if it is face right by default in left controller set it to true then set it back to false in right controller ,else do the opposite.
Here's an example :
ua-cam.com/video/XIEtt4GH_Mo/v-deo.html
for some reason the animation isnt triggering ..i dont know why..the enemy is just standing on idle....i did the code like you did but the enemy wont attack the player
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.
Unity is showing me the same error
Would it not make more sense to make a base Enemy class and then have RangedEnemy and MeleeEnemy inherit from it to prevent copy and pasting your code?
I think you are correct. I know this is a year old, but its awesome when people who are learning think of optimization. Personally, I am glad he did not do it because it allows people learning room to grow.
thANKS NOW I KNOW HOW TO MAKE A TIMER sorry for capslock im to lazy to change them
i want to congratulate you for you r good tutorial ,but i have a little issue :
enemy fireballs dont go into the right direction , and even by doing what you have done at minute 41:00 it didn't worked and i don't know how to fix , do you know something to help me?
for some reason i get the red box but when the player walks into the range of the enemy the attack animation does not trigger and the player doesnt even get damaged.
and i think the root of the problem is the raycast is not detecting the player is there as the animation when the player is in sight to attack is never called.
i have same problem
I have the same problem ;;
no idea if this is still relevant, but I had the same problem and its probably not the best way to solve it but I simply put the distance value (5th one) > 0 and that triggered the animation for me
RaycastHit2D hit =
Physics2D.BoxCast(boxColl.bounds.center + transform.right * range * transform.localScale.x * colliderDistance,
new Vector3(boxColl.bounds.size.x * range, boxColl.bounds.size.y, boxColl.bounds.size.z),
0, Vector2.left, *0.2f* , playerLayer);
Did you ever solve it? And if you did, what did you do?
same Problem, did u solve it?
@@sanjanar6218
Hello, can I ask why my Enemy dissapears when i turn on the game, he goes somewhere under the ground so I cant see him ?
Thank you so much for all these videos! Idk where I’d be without it!!
Do you think you can show us how to make our character go between scenes, like going between levels?
Where did you fix the error where the enemy continues to swing his sword over your body after you're dead?
thank you just thank you man you are just amazing
16:32 Hey, this problem is still there in my game and the melee enemy is not working.
Plz help.
Great tutorial but I have 1 mistake could you help me?
When I kill an enemy he moves far away. What should i do my friend.
When the enemy changes direction, the active projectile flips to the other side relative to the enemy. Is there a fix for this?
'Guess i'll die' lmao you're the best :D
so my problem is with the patrol and attack of the ranged enemy it moon walks left and right (faces the wrong direction its going) and the range doesn't flip with the enemy, i've downloaded the finished copy of this episode to make sure his is working which it is, so i copy and pasted all the code related the the ranged enemy into my scripts so the codes are the same and cross referenced everything in the inspector so all the positions, scales and script inputs are the same but it still broke ...help!
i fixed my problem just by deleting the Ranged Enemy from the Enemy Patrols "enemy" and "enemy animator" functions then putting them back into the Enemy Patrol fixed my problem
the EnemyFireball is not visible when he the enemy shoots but the invisible fireball still hits the player the Sorting layer on the fireballs is set to Foregrounds so idk the problem Please Help someone!
Someone help as soon as possible
Where does string create?: №57/№67 - "invulnerable", because it's string just already done on 47:57 min
already see that in 51:17😁
An easy fix for the firetrap is just to simply change the onTriggerEnter to onTriggerStay =)
14:54 Is it neccesarry to take existing BoxCollider2D and using its properties make damage area. Is it possible to add second BoxCollider2D component just for that purpose or making damage area? Or would it be less optimized to do so?
Hey, great videos by the way. I just have a question which i cannot find the answer to, at 33:02 I clicked on the MeleeEnemy and opened my Animator, but all the animator parameters just vanished. I can't find them. the parameters are there, just no buttons are showing up. My die, is gone, moving, melee, ranged and hurt are vanished. any suggestions?
Yeah, it's a common Unity bug. Just restart it and it should go back to normal
Can’t you just put a script on the enemy that stores the starting position and the allow distance from start, and then do calculations in update to get the patrol behavior? Like is there a reason we need 4 objects just for 1 enemy? Genuine question.
My ranged enemy keeps shooting fireballs even when the player is out of sight while he is walking in the opposite direcetion!
Any reasons for that? thanks for the videos, great tutorials as usual.
Thanks for your tutorial! Is there a reason why you keep using Vector3 for a 2D game?
Glad to help! Yes, Unity mostly uses Vector3 since it's a 3D engine, so it needs 3 coordinates for most functions even or 2D games. There are some exceptions where you can just use a Vector2 but it in my opinion it's just easier to use Vector3 in most places
One question: Enemy can move while he is attacking ( if i move away from it). Is it some quick fix of that?
Did you find the solution?
Awesome videos! Are helping me a lot to learn how to proper use Unity
Hello, can you help? Very necessary!! 1. The enemy continues to hit when he is patrolling and when he killed me. 2. When my character is dying, he continues to move, and when I jump, his image appears, what should I do? Perhaps someone knows...
I have the same issue, did you fix it by any chance?
Nevermind, I fixed it. You just need to rewatch this moment - 32:15. The issue was in health script, so just write code more carefully
Okay
@@stxrmx3548 My enemy hasn't changed, he still beats me when I'm already dead
Hi, I´ve got a question. Where do you got the EnemyProjectile Script???
from the traps video
Hi, I followed the instruction at around 5:08 , i did exactly what the video shows step by step but first, it shows : "Transition Idle - Attack in state Idle doesn't have an Exit or any condition , transition will be ignored" after i added the attack condition my enemy always doing the attack anim and not idle state, Anyone know how to fix?
This is absolute awesome. I have just one question. When i create event on end of animation die when i kill enemy he stop using those two scripts but he will not disapeare and because of the script enemy damage can still hurt me.
Not sure if anyone had this issue but when I would press play the MeleeEnemy would disappear. The only way to get it to work was to change the value of "Near" to -10 in the Clipping Planes under "Main Camera" If anyone knows why this was happening to me/ why this solution fixed the issue, the feedback would be greatly appreciated.
i have a problem, my ranged enemy only shoots fireballs for 1 frame and then they disappear
Same :/
Still not sure what was causing the issue but deleting RigidBody2D component and setting resetTime to 15 worked for me. Hope this helps :D
If anyone else is having issues detecting player with RaycastHit2D change this part "boxCollider.bounds.size.x * range" to this "boxCollider.bounds.size.x" in the second parameter of the BoxCast function. For example:
private bool PlayerInSight()
{
RaycastHit2D hit = Physics2D.BoxCast(boxCollider.bounds.center + transform.right * offset * transform.localScale.x * colliderDistance,
new Vector2(boxCollider.bounds.size.x, boxCollider.bounds.size.y),
0, Vector2.left, 0, playerLayer);
Debug.Log(hit.collider);
return hit.collider != null;
}
Thank you so much for releasing a new tutorial. Been following this series and making my very first platformer! Out of curiosity, why not use the new PlayerInput system for the controls, or the Cinemachine for camera movement?
Hey there, it would've been a bit easier probably but I wanted to start with the basics not use any packages.
I have a problem with enemyPatrol. I was follow your video many times but I can't found what's the wrong is. while on patrol to the left, he walks backwards and the scale doesn't turn to minus. Can you help me please?
Hello, in the firetrap episode you said you corrected so that player takes damage when he steps on to the firetrap and sit there idle. But I folled all your corrections. But still player does not receive any damage when he sits on the firetrap continuously without moving!
Pl give me some hint to solve this issue.
I have a problem with enemy patrol, when i run it enemy turns right but he doesn't move right like for you in the video. Can anyone help?
Edit: My death animation was the issue, it works now
The boxcast/playerinsight function returns true no matter what, even if my player is clearly in the box. I saw that you had IsTrigger activated, but doing so makes my enemy clip through the floor. Really confused, need help!!!
im on the patrol part and for some reason i dont see the enemy when i start the game, unless i disable the animator and than its working good just without the animations of course... any idea what could happen?
switch off trigger in boxcollider2d of character or...
friend, I have a problem, I did everything right and if I came out with an enemy, but when I create another and put the scripts into it, it doesn't hurt, it can perform all the animations but it doesn't hurt the player and it doesn't give any errors, what could it be??
First of, I want to say that you have a great tutorial! I have been following ur first until this video for my personal project. Unfortunately, I'm having an issue in Ranged Enemy AI. Specifically in 40:08, I could not get to play in Unity, as I encountered an error message "UnassignedReferenceException: The variable anim of enemyPatrol has not been assigned." I also see that in 39:48-39:50 in your video, which mentions how you do not have the enemyPatrol assigned. I tried following your tutorials and even tried restarting your video to see the issue, but haven't figure out how to solve it yet. What seems to be the problem and how can I solve it?
Hi, did you find the problem?
@@dezaraogre nvm, its alrdy solved. Thanks for reqching out tho
@@ryanmondong9835 same on me , can u figure out how to solve that ?
wht a legend, still liking my comment even tho the it is 2 months ago
Solution. Disable EnemyPatrol., until Pandemonium turns his back on.
For those looking for the answer.
enemy teleports to location of where i did the animation
edit: i had to apply root motion then it works.
lmao every time i get a problem that the internet cant fix i post my problem in the comments then after a few minutes i find a fix.
but i have another problem where the enemy is staying idle when i go inside the box
You probablly did some animations wrong. And you have to set the right tags on the player as "player" and enemy as "enemy".
please help, i followed exactly your coding and steps but the enemy patrol not moving to the right and left edge. idk wheres the problem
Hey keep getting this in your damage enemy section,
NullReferenceException: Object reference not set to an instance of an object
Nevermind, apparently I may have installed the right extension for it
Hi. I just have a question which i cannot find the answer to, at 47:33 to 47:43 what to do. did not change RangedEnemyHolder to MeleeEnemy. I did not understand this part 47:33 to 47:43. What did you do?. Please help me
Im having some troubles making it turn, for some reason it does the patrol but its not actually turning when it gets to the other side. I check the code and everything seems ok, melee one works, ranged one doesnt.
I've run into a bug that I can't figure out. So the line of sight was working properly with my melee enemy. However in working on the ranged enemy his line of sight is no longer flipping with him. So it starts off fine in the correct direction he's facing. Though the enemy walks backwards rather than forwards. Then when he gets to the patrol edge he turns around but the field of vision gizmo stays the same direction. so if the player is behind him, it triggers the enemy to fire a fireball. However the fireball still fires forward away from the enemy but is triggered from behind the enemy as his field of vision doesn't change. He also continues to walk backwards if you're out of his "line of sight". I've checked all my scripts to yours but they look fine to me. No errors are compiling in Unity. So I have absolutely no ideas on how to fix this issue. I also tried changing his direction of both the ranged enemy and the ranged enemy holder but this only seems to flip the sprite so he may then walk in the correct direction but his field of view still doesn't change. Same issue if I change just one of the objects direction he starts walking the right direction but his field of view stays behind him.
Well update after playing around with the x position on the ranged enemy and Ranged enemy holder I fixed the walking backwards issue. The enemy now flips but I still cant get enemy field of vision box collider/gizmo to flip. So the enemy walks forwards and heading one direction his line of sight is in front of him but the other direction the box is behind him. I know we wrote code to make the box flip too, but again I've checked all my code a few times now and I'm not seeing any errors to fix this issue.
I followed you exactly but the enemy just ignores me and continues to patrol. He does not stop and attack. What could I be doing wrong?
Did you find any solution for this?
I think so…
HELP PLEASE!!!
why changes in scene don't apply in game mode??
Help me, I can't see the Collider Parameter in the scene, it seems to be hidden, I can't see to adjust
41:28 the EnemyFireballHolder script causes the enemy fireballs to shoot at the enemy when it is facing the left. When it faces right, the fireballs shoot to the right. [EDIT] I solved this. Answer is in the reply.
I figured out my problem. I had incorrectly set the game object hierarchy and Firepoint was not a child of RangedEnemy. If you are following along, make sure you're checking your game object Child / Parent structures. I was so tired I didn't realize I had overlooked where it was sitting. Interesting how something so small can have such a large effect.
@@micahburnside2281 Weird im at the same exact problem and firepoint is child of the Rangedenemy and he still shoots himself when facing left
Hey, I didn't wanted the range enemy so I didn't change the way how the script Health works. Will this cause problems for me in the next tutorials? (In my case just the audio tutorial and the chekpoints & respawn tutorials).
Not sure if someone still can answer my question but I got an issue when my player gets hit
The player is out of the range of the enemy but still get damage. How to fix that issue? I am using a linecast to check if the player is in range
@PandemoniumGameDev In the unity console it is displaying that the "animator for the melee enemy has been destroyed but you are still trying to access it" Can you suggest a solution to this
btw love your tutorials
45.02 patrolling behavior is not working. If anyone knows how to fix it please tell me.
Pandemonium, I have a problem with my game. I've typed the code like yours, but the problem in second 23:16 still occurs. Do you have any idea what should I repair?
Having the same problem... Did you get the solution?
@@freestylerak6655 no i did not
@@marutorii no problem bro, I fixed it
@@freestylerak6655 lucky to you
Hi, I had a problem with scaling my sprites. Knight on the video is on transform scale: 1, but my enemies are on scale 0.2 when I want the same height as my dragonknight. Yeah I could resize all my enemies to correct resolution size, but I didnt want to do that. So, the problem: When I resize my enemies - then Gizmos and RaycastHit wasnt same height as my box collider - it was actualy two times bigger.
Fixing this bug was quite easy (But for my dumb brain it was like 40 minutes strugling): You need to add to your new Vector3 transform.localScaleY.
So the code for Gizmos is: Gizmos.DrawWireCube(boxCollider.bounds.center + transform.right * range * transform.localScale.x * colliderDistance,
new Vector3(boxCollider.bounds.size.x * range, boxCollider.size.y* transform.localScale.y, boxCollider.bounds.size.z));
And for RayCastHid2D: RaycastHit2D hit = Physics2D.BoxCast(boxCollider.bounds.center + transform.right * range * transform.localScale.x * colliderDistance,
new Vector3(boxCollider.bounds.size.x * range, boxCollider.size.y * transform.localScale.y, boxCollider.bounds.size.z), 0, Vector2.left, 0, playerLayer);
Sorry if this is stupid or apparent, but I havent seen anyone mention this here.
Also sry for my English, I am just dumb :D
I got everything in this video to work with the exception of the collision with enemies causing damage. My enemies are being treated like solid objects, so my player is blocked by their hitboxes and is able to stand on top of them. Any suggestions as to what can be causing this?
Pretty sure it's a quick fix. Change the colliders on the enemies to be On Trigger
@@PandemoniumGameDev Thankkks
Great Tutorial :D Love it :)
why does my fireball only has short range of distance? it dissapear before even collide with anything
hello i have problem about damage enemy with fireball, fireball not damage enemy but enemy stop moving when i shoot 3 fireball ( i copy/paste you code but not working )
I'm having a problem with my arrowtrap ever since I changed the enemy projectile script every time it hits the player or the wall it stays frozen there and keeps shooting. I think because it's not disabling when it hits anything. Any opinions?
Hi, thanks for the tutorials, very helpful. I'm hoping you can help me with something? My melee enemy is patrolling the space I assigned but he is walking backwards? Any ideas?
same
@@luckytoad3945 try changing the rotation to 180 on the Y axis
Solved the problem when enemy patrol , it's not damaging, put
if (enemyPatrol != null)
{
enemyPatrol.enabled = !PlayerInSight();
}
instead of
(enemyPatrol != null)
enemyPatrol.enabled = !PlayerInSight();
Hope it will help someone, because it helped me.
Thanks
but my enemy doesn't activate attack animation when I go into his red zone, why?
I am trying to figure out how to implement the enemy damage in my code which I have made a few tweaks to to not include player projectiles. I want to handle the damage the same way but just on the mouse click. How would I incorporate that?
Hey man, sorry I'm a little late to the party but I'm having some issues with the enemy patrolling script. I have set up everything they way you have it in the video, assigned all the parameters, however, when I run the game in unity the enemy is teleported to the right edge point, has turned left and is performing the walking animation but not moving. Any ideas you can run by me?
Same here, did you figure it out dude?
Hi love your videos but had a problem in wall jumping tutorial my jumping became infinite again
Can you send me more details on Discord?
I'm making a basic box game and i just wanted to know wether the enemy animation is neccessary for taking damage (wich it probably isn't(i dont really want to make animations because boxes dont usually do anything)) because every time i walk up to the enemy nothing happens. Even when i created an object that should damage the player nothing happened. Also the enemy is invisible even tho it has a sprite renderer.
It seems like i forgot to save the file and it didn't load in unity lol. Now i got a compile error so ill go fix whatever its saying
Dang im too stupid to fix it
Hey i have a problem, when i set my layer to player he free falls through the ground, is there any fix to this?
Sorry, I followed your course. When I did the 41:48 part, I wanted the enemy in my range to be able to shoot arrows, but after he detected the player, although he shot the arrow, it disappeared instantly. Why is this? By the way, I didn't animate my arrows, could it be related to the animation?
I found the problem, my arrow point is too close to the enemy, causing it to disappear instantly when it is shot.
plz, help me, my RangedEnemy can't movement with patrol, when I input RangedEnemyHolder to Patrol he can move around but collider box is not change position.......sorry, my English so BAD =(((((((
i want to ask do you know how can you make character transformation for example like goku from dragon ball love your tutorial btw
Yeah, you have a couple options. 1. Change the entire character sprite or 2. Divide the character into a couple images: hair, chest, arms etc and then change the sprite or color on each individual element like Goku's hair turning yellow.
@@PandemoniumGameDev Does change the sprite effects the animation?
'FireBall (8)' AnimationEvent 'Deactivate' on animation 'Fireball_explode' has no receiver! Are you missing a component? does anyone else get this please i need help
Why i dont see any animation set up for the fireball on explode animation?
Nice tutorial! I finally have my ranged enemy patroling perfectly in the scene but when I try to create a prefab of it to use it in another scene it just don't work for some uknown reason. It keeps patroling but he doesn't attack the player and I have all tags displayed correctly. I thought it was a bug but it does the same in older versions of unity. I just don't find how to solve it!
hey did u fix the bug ? bcz I have the same pb T-T
It could possibly be because the Ranged Enemy does't have any movement logic attached to it alone, that's in the Enemy Patrol script. It seems like anytime I remove/add a enemy to the scene, I need to plug the info into the Enemy Patrol prefab in the hiarchy to make the enemy patrol
Hello. I have a question.
I have a GroundSpawner and EnemiesSpawner and my enemy with isTrigger Box Collider 2D just keps falling down through the platform. How can I solve this problem? Can do it only via coding or there's another solution?
Same problem
Thank you for uploading. May i ask when u will upload the game over??
This weekend I'm finishing the audio & music episode, then the game over screen is coming next week probably.
hey, was just wondering that is there any way to make the player damage the enemy through melee attacks.i followed through all the scripts but i did not wanted to add a projectile attack system but now im stuck as i dont know how to damage the enemies through melee attack
hey, nevermind. after hours of hit and trials and some useful tutorials i was finally able to get my way through it. And btw youre the goat.
@@itsyourgamer3786 Good luck for you !