Unity: Flying Enemy

  Рет қаралды 16,740

Root Games

Root Games

2 жыл бұрын

In this tutorial, we create Flying Enemy with a chase detection area.
✅ 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 #flyingenemy #unity2022 #enemy #rootgames

Пікірлер: 55
@random_precision_software
@random_precision_software 2 жыл бұрын
Nice and easy way of showing it. Good stuff
@irsilvags6369
@irsilvags6369 3 ай бұрын
thanks for the tutorial, i rly like it!
@lizardrain2918
@lizardrain2918 Жыл бұрын
I have no idea why but my player gets stuck on the box collider 2d for the chase trigger. Everything is set to on trigger and my code is fine. But If i place the chase trigger box with enemies it gets them all stuck. If the player touches the box collider 2d he just bounces off. If he is under it and jumps he gets stuck in it.
@leonardopalmerini2516
@leonardopalmerini2516 Жыл бұрын
Excuse me, but my Player does not seem to hear the collider and the enemy remains stationary Any suggestions?
@DrJonesJazzMore
@DrJonesJazzMore 2 жыл бұрын
thanks for the video
@Kira-sd2xm
@Kira-sd2xm Жыл бұрын
Do you have the tutorial to do the animation of bat? I follow you, but my bat doesn’t fly.
@rafarodriguez4765
@rafarodriguez4765 Жыл бұрын
Good!
@leonardopalmerini2516
@leonardopalmerini2516 Жыл бұрын
I don't have a sprite for the enemy but a skeleton animation of Spine App. ... still a great tutorial.
@xDTHECHEMISTx
@xDTHECHEMISTx Жыл бұрын
Do you have anything in the works for "get hit knock back effect? Like castlevania when you get hit by an enemy or jump on them and get knock back effect damage?
@RootGames
@RootGames Жыл бұрын
I covered that in my course on Udemy/Skillshare 😊
@nidulakarunarathna4071
@nidulakarunarathna4071 2 жыл бұрын
very smart way..keep it up
@RootGames
@RootGames 2 жыл бұрын
Thank you, I will 👍
@noobdev6464
@noobdev6464 6 ай бұрын
I have implemented your code and disable the returnstartpos wich is what i want. but how can i make them wondering around instead of staying stationery when i leave the chase area. Also is there a way to make the movement have a ease out while they stop chasing?
@RootGames
@RootGames 5 ай бұрын
You can use Randon.insideUnitCircle to choose random positions inside the radius of the enemy.
@ArtificiellPotatismos
@ArtificiellPotatismos 2 жыл бұрын
I'm having trouble understanding the array in ChaseController script. What excatly are we referring too?
@RootGames
@RootGames 2 жыл бұрын
In this case, the array holds a reference to the enemies. Add enemies you want to control to the array. Then we enable/disable chase for each enemy in the array. Note that the ChaseController script goes on your trigger collider.
@guillermostaudt6452
@guillermostaudt6452 Жыл бұрын
@@RootGames Sorry I have a similar question, when i put public FlyingEnemy[] enemyArray; in my script unity says that "The type or namespace "FlyingEnemy" could not be found"
@RootGames
@RootGames Жыл бұрын
@@guillermostaudt6452 Did you name your script "FlyingEnemy"?If you you different script/class name then it goes "YourName[]" enemyArray;
@guillermostaudt6452
@guillermostaudt6452 Жыл бұрын
@@RootGames Yes it was exactly that, thanks!!!
@marbiox3199
@marbiox3199 2 жыл бұрын
I have a collider that disables when I crouch and he stops chasing, anyway to fix this?
@RootGames
@RootGames 2 жыл бұрын
You need to change the approach a bit. Forget about this big collider. You can add smaller colliders on choke points and there enable chasing. For disabling chasing, maybe detect collision on enemies, when they touch collider on the end of the area, set chase variable to false.
@emilywilkins2922
@emilywilkins2922 2 жыл бұрын
Hey there! Awesome video You just saved me hours lol! I was wondering if you could tell me how to have multiple enemies with their own chase boxes cause right now if I add a new collider and the player enters the area it will just trigger the original enemy who is at a different spot in my level and chase the player. Hope that makes sense.
@RootGames
@RootGames 2 жыл бұрын
When you create a new collider with the ChaseControls script, you need to assign enemies in the inspector (drag and drop enemies you want to be affected).
@squeeziejetadore3800
@squeeziejetadore3800 Жыл бұрын
hello, somehow everything works but the flying enemies don't go back when my player leaves the box collision, is there something i missed?
@RootGames
@RootGames Жыл бұрын
It can be something in your code or it's a problem with detection. If the detection is the problem, select Rigidbody on the player, and set collision detection to continuous.
@maurosanchez1540
@maurosanchez1540 2 жыл бұрын
goood!!!
@vylan903
@vylan903 Жыл бұрын
How would I set up the chase control if I am doing an infinite runner and enemies are getting cloned?
@RootGames
@RootGames Жыл бұрын
Trigger colliders need to be a part of the enemy prefab that you will instantiate, or just make them follow the player by default when instantiated, you can find the player with some tag and pass its position
@user-ig6tr2en3s
@user-ig6tr2en3s 2 жыл бұрын
I am learning well. If it is 3D instead of 2D, where can I edit the script?
@RootGames
@RootGames 2 жыл бұрын
Sorry, but I'm not an expert in 3D games so I wouldn't know 100%. Of course, you need to use 3D colliders and change the code for 3D colliders, the rest of the code should work.
@NoobProMaster01
@NoobProMaster01 10 ай бұрын
Your guide is very useful and simple! But i have one last problem is my enemy don't just Idle in one place but keep following me even i got out of the trigger point, it still just won't return to it starting Point but keep track me to death. What should I do to fix it? The Start Point seem not work.
@RootGames
@RootGames 10 ай бұрын
Assuming that all is good with the code, maybe add the kinematic rigidbody 2d component on "Chase Trigger" object. Also, on the player in the rigidbody2d settings set "Collision Detection" to Continuous
@NoobProMaster01
@NoobProMaster01 10 ай бұрын
@@RootGames I fixed it! Thanks for your advice! Your guide is great! Keep making more guide in the future! Thank you so much!!!!
@rynmc5471
@rynmc5471 Жыл бұрын
hi the chase trigger is not activating the chase when the player enters the box collider
@RootGames
@RootGames Жыл бұрын
Hi, use "Debug.Log" to detect the problem and see what functions are called. I would first check with debug if the collision between the player and the box trigger is detected.
@frideonfriday7725
@frideonfriday7725 5 ай бұрын
Hello! How can you make it so the enemy wont overlap player's sprite?
@RootGames
@RootGames 5 ай бұрын
Hi! Try to add offset to the player (targeted) position. Or just make the movement stop when their colliders/triggers touch.
@tejaskutal2922
@tejaskutal2922 2 жыл бұрын
Very Nice Can you make patrol enemy but only with distance we choose
@RootGames
@RootGames 2 жыл бұрын
I'm not sure that I understand you but try to make a basic patrol enemy that will turn when he detects the wall in front or end of the ground. If you want to manipulate that movement, so that the enemy can't go directly to the wall or to the edge of the ground, you can create triggers that will just collide(detect collision) with enemies. When the enemy enters the trigger, flip him in the code. You can place those triggers anywhere you need. Hope it helps ;)
@orcvs6297
@orcvs6297 2 жыл бұрын
The enemies just freeze after respawning my player clone, how do i fix that?
@RootGames
@RootGames 2 жыл бұрын
This is because the variable GameObject player is null for enemies(since it's destroyed). In the enemy script, we find the "player" in the Start() function and that happens only once, after you destroy it, reference to the player is lost. This approach is for restarting the whole level. In your case, you need somehow tell enemies about the new respawned player. My suggestion is to do it in the ChaseControl since you already have the array of enemies. In addition to setting the chase variable to true, you need to pass them an object(player) that has entered the collider.
@orcvs6297
@orcvs6297 2 жыл бұрын
@@RootGames i am kind of new to coding, how to do it?
@RootGames
@RootGames 2 жыл бұрын
In the Flying Enemy script make this function. public void FindPlayer(GameObject newPlayer) { player = newPlayer; } In the Chase Control script, call that function in the foreach loop like this: foreach (FlyingEnemy enemy in enemyArray) { enemy.chase = true; enemy.FindPlayer(collision.gameObject); }
@orcvs6297
@orcvs6297 2 жыл бұрын
@@RootGames thank you so much, this works on prefabs right?
@orcvs6297
@orcvs6297 2 жыл бұрын
nevermind, it's working. thanks again!!!
@iconic2310
@iconic2310 Жыл бұрын
i have tag player not defined?
@RootGames
@RootGames Жыл бұрын
Create a custom tag or use the tag player. Minute 1:30 in the video.
@omerkara6517
@omerkara6517 Жыл бұрын
how can i find this asset pack?
@RootGames
@RootGames Жыл бұрын
This was made for some old game that never saw the light of day, so there is no site to download it from.
@songediter9101
@songediter9101 2 жыл бұрын
can you please share the codes so we don't make any mistake when we copy it?
@RootGames
@RootGames 2 жыл бұрын
I don't believe that copy-paste is a good way of learning to code. You will learn much more if you do it yourself step by step and understand the process and logic behind the code. Try it, this is a fairly easy challenge :)
@songediter9101
@songediter9101 2 жыл бұрын
@@RootGames thank you for replying
@denisoktaviano1337
@denisoktaviano1337 Жыл бұрын
bro can u help me with this problem 😅 ChaseControler.cs(24,17): error CS0103: The name 'enemy' does not exist in the current context
@TheDumbDonkey
@TheDumbDonkey 4 ай бұрын
For me the flip method wasnt working so i asked chatgpt and did it this way and it worked private void Flip() { if (transform.position.x > player.transform.position.x) { transform.localScale = new Vector3(-1, 1, 1); // Flip horizontally } else { transform.localScale = new Vector3(1, 1, 1); // Reset scale } }
@orramitos
@orramitos 2 ай бұрын
Great tutorial! I'm having issues with adding animations to the script if possible can you help? 🥲
Unity 2D: Scrolling Background
2:17
Root Games
Рет қаралды 19 М.
(FREE COURSE) Make awesome CUTSCENES in Unity using Timeline
41:52
Ну Лилит))) прода в онк: завидные котики
00:51
Sigma Girl Education #sigma #viral #comedy
00:16
CRAZY GREAPA
Рет қаралды 71 МЛН
Indian sharing by Secret Vlog #shorts
00:13
Secret Vlog
Рет қаралды 51 МЛН
How to deal with SLOPES! in Unity 2D using built in Physics
30:07
Enemy Patrol/Wander AI Unity SIMPLE & EFFECTIVE CODE! Tutorial
10:00
TOP DOWN MOVEMENT in Unity!
22:30
Brackeys
Рет қаралды 1,2 МЛН
3D Pathfinding & Agent Avoidance In Unity
7:20
A Bit Of Game Dev
Рет қаралды 16 М.
How To Make 2D Ladders In Unity
4:25
bendux
Рет қаралды 37 М.
Unity Player Death and Respawn Point Tutorial
7:58
MoreBBlakeyyy
Рет қаралды 11 М.
Enemy Patrolling Unity Tutorial
8:28
MoreBBlakeyyy
Рет қаралды 7 М.
Obstacles & Enemies - Exploring Flowlab
7:00
flowlabIO
Рет қаралды 22 М.
Ну Лилит))) прода в онк: завидные котики
00:51