Gonna use this for enemy ai in an ACTUALLY simple game. Went camping, and had to spend the night chasing away raccoons. Was terrifying. Gonna turn it into a simple horror game using only free assets. (Unless I can't find a racoon asset, then I may have to modify a fox one I found, or just use the fox) Gonna take a break from my bigger projects, and make it. Just one non-procedual environment, 2-3 enemy ai, and 2 players.
@@taxesjuicebox I need to. Need to learn Godot enough. Hyperfocusing on making a mon-type set of characters, have an elemental system, and am going through all the inspiration diligently. Already past 550 pokemon I think, and stopped the research today on Zoroark. (Same column as Ninetails and Lucario. Despise Lucario being one of my favorite program, never made the connection between him and the Tanuki Hengeyokai)
Amazing video man this helped me a lot, for my top down 2d RPG I wanted to lock rotation on the Y for smoother looking enemy movement. To do this I removed the last bit of code "transform.rotation = Quaternion.Euler(Vector3.forward * angle);" this doesn't lock rotation but prevents your enemy from rotating 😊
Awesome this is just what i needed, like im making a simple 2d game that needs enemies, currently all enemies shoot me even if i was at the start of level
Me pareció genial, siento que otros vídeos o lo hacían muy complejo o simplemente demasiado simple como para que este satisfecho con el resultado. Este vídeo me pareció rápido y que va directamente al grano aparte de explicar bien y claro lo que esta haciendo durante el trascurso del mismo. 10/10
im getting the error saying " 'Transform' does not contain a definition for 'position' and no accessible extension method 'position' accepting a first argument type 'Transform' could be found" any way to fix this? edit: spelled position wrong fixed now
I'm having an issue with the vector2 movetowards line of code, its giving me a cs7036 error saying something about max distance delta. any clues? anyways your previous tutorials have been great, and so far this is too! earned a sub you have helped me aton. 3:47 is were I am stuck
question about the distance or the movetowards.i dont know tbh basically if i want the whole thing to be on X axis only and i dotn want to use rigidbody to solve it. Can i do it somehow? Also the if statement wont really work in a 2d platformer style game from my experience because the Y axis is equal and the transform.pos has 2 axises right. So how do iput the whole thing on X i tried looking around on forums but i didnt really find an answer.
How would I apply an offset to the position I want the AI object to go towards? Like I can apply an offset but I need the offset to change depending on the direction the player approaches the object. I can't get normalized to work.
3 หลายเดือนก่อน
Is it possible for enemy ai to be drawn to multiple players? What would the code look like?
i have an issue when i try to shoot my enemy i hit the collsion for detecting if they player is nearby but when i try to check what collider it is it doesnt work
Or if you don’t care about obstacle avoidance and want your enemies to just pass through them you can set your enemy’s collider to a trigger and just check for collision on the playet
Great Tutorial! But for unknown reasons adding like 5-7 enemies with this script attached makes my game massively slow down in frame rate. Unchecking the script everything runs smooth. Any ideas for this one? No errors in the console either.
Great tutorial, but is there a way to make the enemy box collider collide with walls? Right now my enemies are working great but they can go through walls the player cannot.
hello! i was trying to do this for one of my school assignments with no coding knowledge, I'm not able to get any of my words to match the mint hue that words like GameObject and vector2 have, was there something i had to set up before hand? im using 2019 microsoft visual studio for this, i dont know if the program is outdated or if this is a different program your using in the video, any suggestions would be great, thanks!
Great tutorial, thank you, but I have an enemy that shoots from distance and I wanted to ask, is there a way to make the enemy stop at as soon as he reaches a certain area?
Hey, very helpful video! Although I'm getting a problem with the AI just moving on it's own in a straight line and not starting where it is placed when the play button is pressed. Do you know anything about this that could help?
Hey great video it really helped but Im having issues as soon as i add colliders into the mix. The enemy doesnt seem to want to follow me anymore as soon as we touch. Have you experienced something similar and could mabye help?
Hello, I have this problem when I want to do the spawnEnemy. When I drag the object to reference the Player I get this error: "Type Mismatch". It's wrong?
So my enemy is going really slow for some reason, I am using it with gravity and a rigid body so I don’t know if that is what is effecting it but anyone got any tips?
Hi! I followed your code, and finally got the opposite result and couldn't reproduce your effect. I double checked the code and made sure there were no doubts. The code does not report an error, but it does not achieve your effect.
for some reason when i use the code in the video to the point where it just chase without rotating it says in the console "the name 'distance' does not exist in the current context any tips on how to fix it
You would need to add this piece of code to your script, which should go under the void Update() method: //Checks for collisions. private void OnCollisionEnter2D(Collision2D other) { //This Checks if your player has the tag "Player". if (other.gameObject.CompareTag("Player")) { //If the collided object has the tag of Player, then the scene loads the active scene, causing a restart. SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); } } To get access to the scene management, you need to import the library for it, by using this: using UnityEngine.SceneManagement;
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Enemy : MonoBehaviour { public GameObject player; public float speed; private float distance; public float distanceBetween; void Start() {
Gonna use this for enemy ai in an ACTUALLY simple game. Went camping, and had to spend the night chasing away raccoons. Was terrifying. Gonna turn it into a simple horror game using only free assets. (Unless I can't find a racoon asset, then I may have to modify a fox one I found, or just use the fox) Gonna take a break from my bigger projects, and make it. Just one non-procedual environment, 2-3 enemy ai, and 2 players.
did you?
@@ironboots Not yet. There was an incident with Unity.
@@rmt3589 did you finish it yet?
@@taxesjuicebox I need to. Need to learn Godot enough. Hyperfocusing on making a mon-type set of characters, have an elemental system, and am going through all the inspiration diligently. Already past 550 pokemon I think, and stopped the research today on Zoroark. (Same column as Ninetails and Lucario. Despise Lucario being one of my favorite program, never made the connection between him and the Tanuki Hengeyokai)
@rmt3589 so much for an actually simple game😭😭 the game dev curse
I'm using this as an "approaching wall of death" for a university assignment lmao, the tutorial was great and simple thanks a lot!
Awesome! Good look with your uni assignment my friend
This was incredibly clear and far less code used than some of the other videos on youtube. Love this.
omg you are amazing , I saw a 17minute video trying to understand this and you made it so simple and you didn't even use raycast like omg
Amazing video man this helped me a lot, for my top down 2d RPG I wanted to lock rotation on the Y for smoother looking enemy movement.
To do this I removed the last bit of code
"transform.rotation = Quaternion.Euler(Vector3.forward * angle);" this doesn't lock rotation but prevents your enemy from rotating 😊
Awesome this is just what i needed, like im making a simple 2d game that needs enemies, currently all enemies shoot me even if i was at the start of level
glad to hear it! make sure to subscribe :)
@@bblakeyyy im already subscribed to ur main channel and your second channel
OMGGGGG, THIS WAS EXTREMELY HELPFUL. THANK YOUUU
simple to follow, full of good info and quick. Love the vid!
Wonderful tutorial, Definetly deserves more views.
Thanks :)
love u, greetings from Poland
Used this for enemy super helpful love ur channel
Me pareció genial, siento que otros vídeos o lo hacían muy complejo o simplemente demasiado simple como para que este satisfecho con el resultado. Este vídeo me pareció rápido y que va directamente al grano aparte de explicar bien y claro lo que esta haciendo durante el trascurso del mismo. 10/10
Yo no hablas espanol. Quiero una hamburguesa con patatas frites
Super neat tutorial, I'm using it for an enemy :)
very nice tutorial, thanks!
im making a game about a frog with this mechanics.gunna be awesome. Using my own art. . .and got a crew member to help work on the poroject
ima use this for just a simple game where squares constantly spawn and you see how long you can survive for
im getting the error saying " 'Transform' does not contain a definition for 'position' and no accessible extension method 'position' accepting a first argument type 'Transform' could be found"
any way to fix this?
edit: spelled position wrong fixed now
very helpful and to the point thank you!
I´m using this on my 2nd "prototype game" where you get chased by some geometric shapes and you try to kill them
Nice 😀it's a great tutorial👌 thank you 💫
Thank you , great video.
Nice Work
nice :) i finally have a enemy that approaches me and kills me
I'm having an issue with the vector2 movetowards line of code, its giving me a cs7036 error saying something about max distance delta. any clues? anyways your previous tutorials have been great, and so far this is too! earned a sub you have helped me aton. 3:47 is were I am stuck
Very usefull tutorial, thanks !
Good job!
Awesome!
Used it for an enemy you are amazing
Vector2.Distance doesnt work for me
pls help. btw im using 2021.3 version
question about the distance or the movetowards.i dont know tbh
basically if i want the whole thing to be on X axis only and i dotn want to use rigidbody to solve it. Can i do it somehow?
Also the if statement wont really work in a 2d platformer style game from my experience because the Y axis is equal and the transform.pos has 2 axises right.
So how do iput the whole thing on X
i tried looking around on forums but i didnt really find an answer.
How would I apply an offset to the position I want the AI object to go towards? Like I can apply an offset but I need the offset to change depending on the direction the player approaches the object. I can't get normalized to work.
Is it possible for enemy ai to be drawn to multiple players? What would the code look like?
thx for this i love you
Do you know of any way I could slow down how fast the enemy rotates? Great tutorial! 👍
Take a look into Lerp and Slerp functions, there's a bunch of great info about rotation smoothing👌
i have an issue when i try to shoot my enemy i hit the collsion for detecting if they player is nearby but when i try to check what collider it is it doesnt work
A useful and fun video from which I have benefited a lot but how can I make the enemy skip the walls and not hit them?
You’ll need to use pathfinding for that
Or if you don’t care about obstacle avoidance and want your enemies to just pass through them you can set your enemy’s collider to a trigger and just check for collision on the playet
Thank you I've got the answer 😊I didn't expect you to be quick to reply, Wow.😅
Noice!
Great Tutorial! But for unknown reasons adding like 5-7 enemies with this script attached makes my game massively slow down in frame rate. Unchecking the script everything runs smooth. Any ideas for this one? No errors in the console either.
upgrade ur pc/laptop
I can't change the enemy speed. It will always have the same speed no matter if I change it
Good job
Thank you!
how do I add collision in this enemy AI, right now it just goes through walls :/
Box Collider
@@takivazquez2836 bruh it is not working that is why i asked -_-
the walls also need to have a collider you know that right? and also check if the collider is only a trigger or not
How do I make so that it works w/ your previous tutorial on to make a basic 2D Game
how can i check if the player is on the right or left of a given object so i can relate to each differently?
Great tutorial, but is there a way to make the enemy box collider collide with walls? Right now my enemies are working great but they can go through walls the player cannot.
To do this you need to move your enemies through a rigidbody. Rigibody.add force or rigidbody.velocity
@@morebblakeyyy Thanks!
This video fucking eazy and usefull, fucking love it
Glad to hear it!
This is amazing🥲 ! Thank you I’m gonna give you credit in my game.. I’ve used your info before
hello! i was trying to do this for one of my school assignments with no coding knowledge, I'm not able to get any of my words to match the mint hue that words like GameObject and vector2 have, was there something i had to set up before hand? im using 2019 microsoft visual studio for this, i dont know if the program is outdated or if this is a different program your using in the video, any suggestions would be great, thanks!
nope its just that he uses a lot of coding so his visual studio remembers , its okay if yours doesnt have colors or suggestions !
What visual studio add-on u using which shows u things u can add like intellisense?
It’s just the most recent version of visual studio. It’s scary sometimes how accurate it is hahaha
@@morebblakeyyy oh ok, I'm still using 2019 that's why haha
@@morebblakeyyy lol I thought you were using copilot
you're the best
Great tutorial, thank you, but I have an enemy that shoots from distance and I wanted to ask, is there a way to make the enemy stop at as soon as he reaches a certain area?
Take a look at Vector2.Distance
You can use this in if statements to check for distance between to objects, and change behaviour upon that
The enemy is flipping to the wrong direction. I tried adding the enemy in a empty game object and turning it too but it would always snap back
same
@@tjthegamer6365 I fixed it. You hsave to rotate the enemy 90° in the code
Hey, very helpful video! Although I'm getting a problem with the AI just moving on it's own in a straight line and not starting where it is placed when the play button is pressed. Do you know anything about this that could help?
Gravity?
ty is very useful
Do you know a way i could stop it from following the player in the air?
very usefull thank you
Thank You
Hey great video it really helped but Im having issues as soon as i add colliders into the mix. The enemy doesnt seem to want to follow me anymore as soon as we touch. Have you experienced something similar and could mabye help?
if you mean that when you add a rigidbody2d and smack the enemy that it just flies off in to oblivion, try adding linear drag of like 5 or so
Hello, I have this problem when I want to do the spawnEnemy.
When I drag the object to reference the Player I get this error: "Type Mismatch". It's wrong?
So my enemy is going really slow for some reason, I am using it with gravity and a rigid body so I don’t know if that is what is effecting it but anyone got any tips?
Change the speed when you click the enemy and scroll down to the script?
or on the float speed do = any number
Is there any way to look it to only the x position for movement thanks
This is great I'm using it for a zombie.
same
Hi! I followed your code, and finally got the opposite result and couldn't reproduce your effect.
I double checked the code and made sure there were no doubts. The code does not report an error, but it does not achieve your effect.
Good day, RimuruDev channel is in touch. This is how it works: (distance > 4).
for some reason when i use the code in the video to the point where it just chase without rotating it says in the console "the name 'distance' does not exist in the current context any tips on how to fix it
you need to declare the variable distance first, outside of the void udpate.
public class chaser : MonoBehaviour
{
private float distance;
etc.
cann you make it wherre it rrestarts when you touch it
You would need to add this piece of code to your script, which should go under the void Update() method:
//Checks for collisions.
private void OnCollisionEnter2D(Collision2D other)
{
//This Checks if your player has the tag "Player".
if (other.gameObject.CompareTag("Player"))
{
//If the collided object has the tag of Player, then the scene loads the active scene, causing a restart.
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
To get access to the scene management, you need to import the library for it, by using this:
using UnityEngine.SceneManagement;
@@neapy9832 your a legend
hi ! nice tuto ! is anyone got a problem with the quaternion.Euler and the vector3 ? this can't be converted no ? tx
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
public GameObject player;
public float speed;
private float distance;
public float distanceBetween;
void Start()
{
}
void Update()
{
distance = Vector2.Distance(transform.position, player.transform.position);
Vector2 direction = player.transform.position - transform.position;
direction.Normalize();
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
if (distance > distanceBetween)
{
transform.position = Vector2.MoveTowards(this.transform.position, player.transform.position, speed * Time.deltaTime);
transform.rotation = Quaternion.Euler(Vector3.forward * angle);
}
}
}
THANK YOU SO SO SO SO SO SO MUCH YOU SAVED MY LIFE
does this also work to make friendly character following us?
yep!
The video is great!
Please check again, I can't download the project
how do you store the public GameObjekt in a prefab?
drag the gameobject into the assets section at the bottom.
thanks
it tells me that i dont have a transform
Make The capital T a t
the speed is so slow how can i change it thanks
public float speed = whatever number;
Good afternoon, the RimuruDev channel is in touch. If the code doesn't work for you, fix it like this) : (distance > 4).
Can Someone give me the script I have Errors :(
Anyone had error code cs1503 at 2minutes 47 seconds
Whats the full error code
Teşekkürler
Am i the only one who this didn't work for?
What issues are you having?
@@morebblakeyyy Figured it out, I'm a moron and put 2: " ; "
2:47
😌 P*R*O*M*O*S*M!!
Amazing and freaking easy
But what if I want the enemy to go back to their place when they stop chasing the player?