Unity 2D Game Basics - Enemy AI - Chasing

preview_player
Показать описание
In this video we will look at how to have our enemy chase the player.

Bookmarks:
:30 Overview of what we want to do in this video
1:07 SpiderAI script - Variables
2:00 Check to see if spider is close enough to start chasing
3:45 Turn and move towards target
8:50 Setup up spider in Unity editor
9:17 testing it out

Рекомендации по теме
Комментарии
Автор

Very helpful series, these videos are underrated.
These channel deserves more subs and likes!

dennisgonzales
Автор

Thanks for this video!! You're my hero thanks a lot!! more power

angelitoencinas
Автор

Hey thanks a lot for the video!! help me a lot with the AI of my game, thanks a lot!

jorgeivfu
Автор

I'm having a problem when i create an enemy in another scene (which is the scene 2) and when i go to that scene the enemy isn't chasing my character but instead it goes to a some point in the scene and when i go back to my scene 1 I'm getting a nullreference exception in the transform. it says that the transform is destroyed but im still trying to access it. Please help. Thank you.

cyrusrendal
Автор

Just want to ask, when you chase, you have used DistanceToTarget, and when you attack in the next vdo, you gave another variable DistanceToPlayer.... Can't we use a single variable??

snigames
Автор

Hello mate, this its cool to add on games, but its not work right, if player leave the screeen and other the enemy cant see the target any more, i have try to make a fix on it but its seen not to work, if main screne got a mob whit the target on player, and you move the same mob to a other seen its cant see the player anymore and well not chase the player anymore ... can you make a fix on that ?

romanegamer
Автор

Thanks, how can I use <colider >in this script for enemy follow ?

sajjadsiavashi
Автор

What should i change if i have a sidescroller and want to limit the enemy to only be able to walk on the ground and not wander around in the air when the target enters the chase range?

ViktorFackel
Автор

Hi, the script works well and the AI collides with player as intended. However my enemy AI only collides with the player and nothing else (i.e. does not collide with boxes placed between the player and the AI. What should I do to make the AI collide with other objects? Thank you in advance!

TheMaiii
Автор

Script is perfect works without an issue but I dont want my character to turn 360 degrees while following the target I want to make my character follow the target and play the animations that I want (I mean I have 4 directions' animations and they will be played as where character goes.)

HyrotoXaque
Автор

You did a really great work, man. My enemy has a human form and therefore I need the transformation.rotation to remain at 0, how could I do it?

Mush
Автор

Hi,
I got a question and i hope you to help me to figure out.
My enemy is randomly showed up.After i add script on that, there is no object to put in my 'target'.

Kmf
Автор

HI MATE! Can i use this codes for my platform game? I try this codes but it just stick with my character (like your skeleton) it just stick with the enemy and pushes it away until they fall down from the platform, please help thanks.

jerdg
Автор

Is there any video that the ai is chasing you even when jumping? Thanks a lot!!

angelitoencinas
Автор

Ok it worked. Actually i did this in a visual scripting plugin and it worked But i have one question. According to this method of yours enemy overlapse my character despite of having Circle collider. Why? Any solution for that?

sanketvaria
Автор

How add a colliderEnter to this scrip for spesific actions?

sajjadsiavashi
Автор

Here's to save you folks from copying:



        float angle = Mathf.Atan2 (targetDir.y,  targetDir.x) * Mathf.Rad2Deg - 90f;

        Quaternion q = Quaternion.AngleAxis (angle,  Vector3.forward);

        transform.rotation = Quaternion.RotateTowards (transform.rotation,  q,  180);




That's not all but...

mizutani_
Автор

Hello, Help me, i not can create animation enemy, ir does not receiver animation change value.
In your vídeo she's doing the animation right side but you not show how you did it Help me please.

Thomasfoz
Автор

When the anemy touch me it will keep rotating what i do?

numeinteligent
Автор

how would I change this to work in 3d?

ElementGuns
welcome to shbcf.ru