To some who's bullets also dont follow the players movements check that the rigid body in code (the variable declared as rb) is the same as your character uses. For example mine was RigidBody2D so I had to alter the code to be rb = GetComponent(); rather than rb = GetComponent();
it was a good video. thanks for helping me If I hadn't seen this video , the way that I used to detect player at a range was triggering the player with some collider😂
great, I managed to make a homing projectile ( a shuriken that I've animated in piskel so the tutorial about the rotation was not used because the shuriken is already spinning), but instead of the enemy, it was the player doing it, foreach and length to calculate the nearest target so I can have multiple targets
Hello this video is really saved me hours thank you for the tutorial. I have a one simple question, in around 9:30 you use distance for shooting the player when it was near, I used collision box 2d and works the same but I really wanted to know which one is better for performance?
tip if your bullet isn't shooting at the position you want it to shoot it at drag the bulletpos to the rifle (this is shown in the vid but I'm saying this in case people missed)
I got this error " Missing Reference Exception: the object of type 'GameObject' has been destroyed but you're still trying to access it" and my bullet didn't spawn.
I don't know why at the start even though I am outside of its detection range, IT STILL HITS ME WITH ONE, SINGLE BULLET. Then, everything works normally.
Basecaly, all you have to do is check if the player transform.x is greater or lower then the enemy transform.x. If the player transform .x is greater than enemy transform.x, set the enemy sprite.flipx to false, if its lower, to true. Hope this helps.
i have a problem that when the bullet hits my player, the healthbar doesnt lower and the bullet doesnt also get destroyed after it hits me, i wonder that the bullet even touches me?
Great tutorial! Though I have a question wether its possible to tag all entitys with the same tag and have them shoot eachother without the bullet going for its parent. Basicly, exluding its parent from finding all objects of the same tag. Or a Minecraft skeleton shooting other Minecraft skeletons. Thanks!
You're so quick i can't keep up imo. If your teaching beginners I would reccomend going a bit slower. I found it difficult to keep up and fully understand what you was doing
You mean the bullet not destroying itself after colliding with the player? If so, put a BoxCollider2D on your bullet prefab and that should solve the prob.
I get this error NullReferenceException: Object reference not set to an instance of an object EnemyBullet.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/EnemyBullet.cs:35)
I love the explanations for each thing you add, very nice tutorial!
To some who's bullets also dont follow the players movements check that the rigid body in code (the variable declared as rb) is the same as your character uses. For example mine was RigidBody2D so I had to alter the code to be rb = GetComponent(); rather than rb = GetComponent();
THANK U SO MUCH DUDE. I TOOK ME 6 HOURS to figuring why my projectile wont move. Such a lifesaver my guy
One of the best enemy tutorials, thanks
Awesome! Works like a charm!! :)
The rotation of the bullet has saved my ass! thank you sir thumbs uppp
Very helpful, thank you very much.
great tutorial, nice and simple, thank you 👌
Really nice thanks so much !
thank you sir, this tutorial really help me
it was a good video. thanks for helping me
If I hadn't seen this video , the way that I used to detect player at a range was triggering the player with some collider😂
great, I managed to make a homing projectile ( a shuriken that I've animated in piskel so the tutorial about the rotation was not used because the shuriken is already spinning), but instead of the enemy, it was the player doing it, foreach and length to calculate the nearest target so I can have multiple targets
Great Tutorial, I am happy it works... The maths are not my strong point after all :P
Saved my game, i subbed
Thank you very much, it helped me a lot.
Thank you so much
i have a problem where the game freezes when the player dies and said the object is not set to an instance
Hello this video is really saved me hours thank you for the tutorial. I have a one simple question, in around 9:30 you use distance for shooting the player when it was near, I used collision box 2d and works the same but I really wanted to know which one is better for performance?
tip if your bullet isn't shooting at the position you want it to shoot it at drag the bulletpos to the rifle (this is shown in the vid but I'm saying this in case people missed)
nice, very helpful
the best tutorials
Thanks for this video
I got this error " Missing Reference Exception: the object of type 'GameObject' has been destroyed but you're still trying to access it" and my bullet didn't spawn.
Do you happen to find the solution?
I don't know why at the start even though I am outside of its detection range, IT STILL HITS ME WITH ONE, SINGLE BULLET. Then, everything works normally.
Fixed the problem! REMEMBER TO DELETE THAT SPRITE FROM THE HIEARCHY!
@@lolerishype It said that in the video :|
Hallo! Great video! Where can I find the video how to create this from scratch and also download assets?
Can you make a video on 2d enemy ai? Not top down like you did before
very helpfull😀
I have problem I did what you tell but only the rotation doesn't work for me
I’m having a problem where it says “the name ‘transform’ does not exist in the current context”
Advice or syntax for this with a 3D object and with coroutine.
I followed the tutorial step by step but the enemy is shooting bullets towards the foot of the player. Could someone tell me what is going wrong?
What should I do if I want to make the enemy only shoot forward?
Is There a way that when you die you respawn when the bullet hits you and your health is 0??!
Projectile is not visible in game view and it's z value is automatically set to -19.8 while is being spawned pls help
Do you know a simple script so the enemy will rotate towards the player?
Basecaly, all you have to do is check if the player transform.x is greater or lower then the enemy transform.x.
If the player transform .x is greater than enemy transform.x, set the enemy sprite.flipx to false, if its lower, to true.
Hope this helps.
I have the problem with the bullet, when it collides with the player it doesnt destroy, it flies by the player
add rigidbody2d to the bullet and even player
i have a problem that when the bullet hits my player, the healthbar doesnt lower and the bullet doesnt also get destroyed after it hits me, i wonder that the bullet even touches me?
nvm i solved it with the help of chatgpt
the little bullet doesnt go towards my player
float distance = Vector2.Distance(transform.position, enemy.transform.position);
It doesn't work, it show a mistake in Console...
Hi there, when my player dies the camera also goes away, how do I make the cam follow my player and not get deleted with the player?
Nevermind I fixed it
@@troutki how? i have the same problem
Great tutorial! Though I have a question wether its possible to tag all entitys with the same tag and have them shoot eachother without the bullet going for its parent.
Basicly, exluding its parent from finding all objects of the same tag. Or a Minecraft skeleton shooting other Minecraft skeletons. Thanks!
Does this work for top down?
Should do!
Any idea why my enemy shoots at the player's feet instead of sprite's center?
Most likely the pivot point of your sprite is at its feet
@@morebblakeyyy Thanks! That was the issue :)
hi I have a problem , my enemy's projectile doesn't damage the player
u find a solution? i have the same problem
My enemy projectile can damage the player but the projectile goes through the player it doesn't land on the player
You're so quick i can't keep up imo. If your teaching beginners I would reccomend going a bit slower. I found it difficult to keep up and fully understand what you was doing
you have misspelled the OnTriggerEnter2D. it is supposed to be onTriggerEnter2D
That’s false, it’s OnTriggerEnter2D.
@@morebblakeyyy I have the problem with the bullet, when it collides with the player it doesnt destroy, it flies by the player
Can i use the script for my player so it can aim without touch controls?
Should work...
6:02
hi i have problem with the collision can u help me
You mean the bullet not destroying itself after colliding with the player? If so, put a BoxCollider2D on your bullet prefab and that should solve the prob.
Have you figured it out?
@@LcyTH-cam I'm also curious now
@@lettuce_justice9263 Are you struggling? Maybe I can help
@@LcyTH-cam Thanks for the offer, luckily I managed to fix it 5 mins later, had a missing piece, thanks anyway!
Bullets dont vanish after 10 seconds. How to fix that?
pretty sure its destroy(bullet,10) the first thing in brackets is the object the second thing is the ammount of time before its destroyed
U use the destroy function, example:
Destroy(bulletGameObject, 10);
This code has to be implemented in the bullet script
@@UnsupervisedIdiotOfficial thanks
@@neilaszemgulys6754 no worries
nhung em lam mai khong duoc
спасибо вам огромное (из России)
Ха-ха, Я тоже 句‿句
Пожалуйста :)
I get this error
NullReferenceException: Object reference not set to an instance of an object
EnemyBullet.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/EnemyBullet.cs:35)
Have you fix that? I’m struggling to resolve it
Have you fixed?
@@T0D4S yes
@@Eastyoffutt yes
@@MAS9Nine how
grx
the bullet going another way from the player
Then set the force to the opposite number, example: if force is 10, set it to -10.
Hope this helps
Does it work for 3d?
No, it'll not work....
@@UnsupervisedIdiotOfficial bro. I’ve already tried that out. It was 5 months ago
I was just trying to help bro...
What the name of the game?
He is making a game silly