Enemy AGRO AI System in Unity For Beginners ( 2D Game Dev Tutorial )

Enemy AGRO AI System in Unity For Beginners ( 2D Game Dev Tutorial )

Lost Relic Games

4 года назад

54,137 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@Gabi-tq9ij
@Gabi-tq9ij - 15.07.2023 18:54

I love you

Ответить
@gececiyim87
@gececiyim87 - 09.12.2022 17:54

hello again my friend,

The enemy character is following, but while falling vertically, it goes down slowly while on top of the player.

I want it to fall on me, what are we going to do?

thank you.

***If I couldn't explain it fully, I can send the screenshot as an e-mail.

Ответить
@gececiyim87
@gececiyim87 - 17.11.2022 10:33

thanks bro !

Ответить
@lastone2841
@lastone2841 - 27.08.2022 07:38

Great video and teacher I'm having this issue the enemy's follow me but when I jump on them they just fall through the floor , and when i jump off a platform they just keep following me floating. Just starting to get back into game dev. :)

Ответить
@Jeea84
@Jeea84 - 26.07.2022 17:16

John, please do a full fledged enemy controller, with melee, ranged, flying options.... including the animations. You must have done it for your game.
You're so easy to follow, I want to learn from you.
Thanks.

Ответить
@jeffaction9968
@jeffaction9968 - 06.07.2022 16:17

Thanks for this video. How can I make it so that the enemy stops when in attacking range as well as when it is not in aggro range. Because right now he is still running towards the player and when I leave the aggro range it will then do the animation for attacking

Ответить
@orionisaacs9864
@orionisaacs9864 - 03.07.2022 22:30

Great video, Do you have a video making a basic finite state machine for enemy AI. Thank you.

Ответить
@vincentdcn
@vincentdcn - 14.06.2022 04:58

In the immortal words of Mr. Burns... "....Excellent."

Ответить
@snaik5947
@snaik5947 - 17.05.2022 02:52

Thanks, nice tutorial.

Ответить
@LCStudiosMC
@LCStudiosMC - 02.04.2022 13:49

Thanks

Ответить
@HeDidWhatNow
@HeDidWhatNow - 31.03.2022 03:17

I'd really like a version of this for 3d rigidbodies. Great video though!

Ответить
@mattrav8127
@mattrav8127 - 22.03.2022 20:06

For issues with enemy vibrating back and forth, while player is above, I added this to ChasePlayer:
if (transform.position.x - player.position.x <= 0.5f && transform.position.x - player.position.x >= 0f)
{
StopChasingPlayer();
}

Ответить
@oveysazimi5516
@oveysazimi5516 - 17.03.2022 23:43

Damn Son Where'd ya find this

Ответить
@supertenchoo4271
@supertenchoo4271 - 12.03.2022 14:16

Great tutorial

Ответить
@vakous2415
@vakous2415 - 09.03.2022 19:09

good man cool video thank you

Ответить
@tando4563
@tando4563 - 23.02.2022 11:45

this is best tutorial i have ever seen, thanks a lot. 👌

Ответить
@IBeToxic
@IBeToxic - 13.02.2022 09:35

TURNNNN ON DARK MODE PLEASEE

Ответить
@codingkricket910
@codingkricket910 - 23.12.2021 19:52

Great tutorial! So my plan was to set my enemy active when its in the distance and disable it when its not. I did the if statments and inside I put gameObject.SetActive(true); if disttoplayer<aggrorange and in the else I put gameObject.SetActive(false); When I go out of the range it turns off but never back on (I'm guessing its becuase it is turned off so the script isnt running) , any idea on how to fix that?

Ответить
@xDTHECHEMISTx
@xDTHECHEMISTx - 07.12.2021 10:21

This tutorial worked flawlessly for me. i have 3 different enemy AI types now

Ответить
@hhcdghjjgsdrt235
@hhcdghjjgsdrt235 - 23.11.2021 16:27

Most underrated unity tutorial channel. Its more simple than triggerenter,stay and exit.

Ответить
@hahaimyourhandlenow
@hahaimyourhandlenow - 14.11.2021 22:13

idk why but it just didnt work

Ответить
@plop2453
@plop2453 - 23.10.2021 21:14

Great video! But whenever I get directly above or below the enemy, it starts flipping back and forth really fast because it can’t decide which direction to go. Any ideas?

Ответить
@aykens3197
@aykens3197 - 04.09.2021 05:41

hello anyone have some problem like mine did? my enemy keep spinning like crazy when i jump over it to the left but it's normal when i jump over it to the right. i've followed the tutorial precisely thou. really strange

Ответить
@g4b7uz
@g4b7uz - 28.08.2021 00:56

Thanks!

Ответить
@Brick69
@Brick69 - 23.08.2021 13:06

Hemos this doesnt seem to work on prefabs

Ответить
@mcdocs2114
@mcdocs2114 - 13.08.2021 09:06

you remind me of john wick

Ответить
@fraan9810
@fraan9810 - 20.07.2021 08:31

Tnx so mush good video

Ответить
@MrMoney-zu6su
@MrMoney-zu6su - 19.07.2021 16:31

I have a problem, when I entered "transform.localScale = new Vector2 (-1, 1);" when the enemy rotates his scale becomes huge

Ответить
@phonike
@phonike - 10.07.2021 23:31

Good Tips

Ответить
@VikingDragon01
@VikingDragon01 - 09.07.2021 21:02

Thank you so much for this awesome tutorial! This helps immensely!

Ответить
@JuanFranco-mq7js
@JuanFranco-mq7js - 08.06.2021 00:03

the code works perfect, but the enemy falls so slow any hint?

Ответить
@MikeCedillos
@MikeCedillos - 03.06.2021 19:44

here is a script for up-down games you might have t change it a little for you're game Mabey using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Enemy : MonoBehaviour
{
[SerializeField]
public Transform player;
private Rigidbody2D rb;
private Vector2 movement;
[SerializeField]
public float moveSpeed = 5f;
[SerializeField]
float agroRange;



void Start()
{
rb = this.GetComponent<Rigidbody2D>();

}


void Update()
{
float distToPlayer = Vector2.Distance(transform.position, player.position);
Vector3 direction = player.position - transform.position;
direction.Normalize();
movement = direction;
if(distToPlayer < agroRange)
{
moveCharacter(movement);
}
else
{
StopChasingPlayer();
}
}

private void StopChasingPlayer()
{
rb.velocity = new Vector2(0, 0);
}

void moveCharacter(Vector2 direction)
{
rb.MovePosition((Vector2)transform.position + (direction * moveSpeed * Time.deltaTime));
}
}

Ответить
@adambouches7396
@adambouches7396 - 19.05.2021 22:35

how would you do this with the y axis

Ответить
@justinchap8732
@justinchap8732 - 22.04.2021 19:21

INSANE thks you !!

Ответить
@hentoebill1506
@hentoebill1506 - 13.04.2021 19:12

how can i make it go on the y axis as well

Ответить
@MLaurenavicius
@MLaurenavicius - 28.03.2021 01:05

That's awesome!

Ответить
@bakiprogamer6595
@bakiprogamer6595 - 23.03.2021 14:18

thanks!

Ответить
@gamewood7800
@gamewood7800 - 21.03.2021 19:16

I love You, you are amazing

Ответить
@noniceq2096
@noniceq2096 - 13.03.2021 02:17

when i do prefab the enemy forget about player (None Transform)

Ответить
@cyclo_studios4229
@cyclo_studios4229 - 14.02.2021 18:19

Thanks keanu love your tutorials

Ответить
@davidbarnaba7229
@davidbarnaba7229 - 25.01.2021 17:40

this is the third video I watch to code a damn aggro, nothing worked, the enemy is standing still doing nothing. What can it be?

Ответить
@elijahlittrell7241
@elijahlittrell7241 - 23.01.2021 07:22

for a cleaner script. "don't" serialize the variables, and instead start each with "public" (including the rigidbody2d) and instead of the GetComponent with the rigidbody2d (in the start function), just add the same way you did with the player transform. hope this helps.

Ответить
@Abdul-pe5rf
@Abdul-pe5rf - 04.01.2021 07:07

Best tutorial please make more I love it<3

Ответить
@totallyrandompersob1664
@totallyrandompersob1664 - 02.01.2021 01:56

If you have your scale higher than 1 on your enemy, and then it calls the transform.localScale = new Vector2(1, 1); my enemy just turns small. I think that's the problem but I dont know how to fix it. Could I change the size of my enemy without doing it in the transform? Also it looks the opposite way of where the player is once it finds it. (still chases it though, just backwards and small).

Ответить
@memesworld8870
@memesworld8870 - 29.12.2020 17:59

I know this comment is a bit late but if anyone can help plz do it..so the problem is my enemy squeezes when the player enters the range.other than tht everything works fine

Ответить
@batuyilman2533
@batuyilman2533 - 25.12.2020 18:39

Thank you man

Ответить