Unity Create a Game Series (E06. enemy attacks)

preview_player
Показать описание
In episode six we implement enemy attacks.

FAQ:
Q: Game crashes when enemy attacks
A: Make sure that the yield statement in the UpdatePath coroutine is OUTSIDE the currentState == State.Chasing condition.

Source code:

Follow me on twitter @SebastianLague
Рекомендации по теме
Комментарии
Автор

Hey, welcome to episode 6 - enemy attacks. I hope my explanations were ok this video - I feel like I might have been a little unclear on some points... Let me know! :)

A huge thanks to everyone who has supported so far!

SebastianLague
Автор

coroutine, navmesh system.. I can't believe how much super useful content in one series compares to the garbage in udemy stuff lol.

and you also used vectors instead of simple float/int variables to make the player/enemy move, which is basic linear algebra stuff but understands them will be important for shaders as well.. man, I HOPE my university will hire you for this stuff... and the animation using Lerp with a math function... and this is a tutorial 4 years ago... :( how far I can code like this elegantly.. just typing along with you helped me learnt a lot, , ty again

Noob-ncjq
Автор

Q: Game crashes when enemy attacks
 A: Make sure that the yield statement in the UpdatePath coroutine is OUTSIDE the currentState == State.Chasing condition.
or
currentState = State.Attacking;
 StartCoroutine(Attack());
currentState = State.Chasing;

chelarucatalin
Автор

This series is absolutely fantastic, I have been trying to get into unity as a developer for years but other tuts are so slow paced. Perfect for anyone coming from a development background.

NightTerrorsNetwork
Автор

I was wondering if you can help me out in 9:25 of the video . Instead of I trying to make this work with a box collider. Can you help please.

tonydelacruz
Автор

Hello there. I was following your tutorial just fine and my code works but having trouble understanding your explanation at time 10:22 on line 75 and 76. You wrote:

Vector3 dirToTarget = (target.position -
Vector3 targetPosition = target.position - dirToTarget * (myCollidionRadius + targetCollisionRadius);

Could you explain in some other way? Really appreciate it.

khaliesahismail
Автор

Old vid, but great. :)

A quick note on state machines. Enums and switch/if statements are fine for simple games, but once you start to make something more complicated, you may want to look into making states into objects using polymorphism, and the factory pattern for updating/changing states. That way, if you make a change to something, you won't have to possibly look through many scripts to update them. If you add/remove states, you just need to edit the factory, and if you change how a state acts, you only need to update a single object.

A quick example is how he has the two IEnumerables in the one class, and needs to check to make sure he's in the right state in one of them. Why do that when the state object itself can call the right one, and not even worry about the second one, because it will be in a different object.

easyBob
Автор

At 11:34 my Enemy still goes into the player itself, any help?

decentcarp
Автор

tutorials are always great thanks, this one I think you might have gone a little to fast on the explanations so it was a little confusing especially when it came to the math. other then that great work!
I'll be showing my support!

belleluze
Автор

Im getting this error
NullReferenceException: Object reference not set to an instance of an object
Enemy.Update () (at Assets/Scripts/Enemy.cs:40)

Apparently this line isnt functioningtarget = why but it never assigns it to the player. It worked for a bit until i added attacking

wbeecroft
Автор

Anyone still around here to answer a question? I'm following this tutorial and it seems that whenever an enemy Lunges at the player, it isn't lunging at the player but the position is being set to a location above the player and then it comes back to the player then every time it lunges it goes back to this location above the player.

vtum
Автор

When you create the State enumerator, are the values inside 'State' type. I thought State was just the variable name and not the type. In the C# documentation is says to specify type after the name,
example: public enum States : State {Idle, Chasing, Attacking}.
Is the enum variable name and the data type of its values both 'State'?

dylanlewis
Автор

So i have everything working but the enemies are attacking from across the map. I have my player and spawner on diffrent sides of the map and when an enemy spawn it lunges across the map and its color is red. Dont know how to fix this please help.

vivighostbadkali
Автор

I don't know why, but I'm at 9:05 in this video, and when the enemy lounges, it hits my character, then goes back to its original position, then Unity crashes. I have no clue what is causing the crash. I've gone back and checked twice, my code is exactly like yours.

morphman
Автор

I love this series !
I added at the end of the start method of the enemy this line:
pathFinder.stoppingDistance = pathFinder.radius + + attackDistanceThreshold / 2;
I also modify this line in the coroutine Attack() : while (percent < 0.5f) and add this line at the end : transform.position = original.position;

It allows enemies not to enter the player's body in Chasing mode and nicely to attack.

jean-michel.houbre
Автор

Could someone possibly explain to me why we have to square the disToTarget? Thanks

bazzboyy
Автор

1:00 Is there a reason why .sqrMagnitude is better than .magnitude?

bimboleiro
Автор

why not to use capsule collider as trigger, with a bit bigger radius ?

deniskhomenko
Автор

Why are you using both "pathfinder.enabled = false" and the State.Chasing or State.Attacking in UpdatePath? Wouldn't currentState == State.Attacking be good enough to suspend the movement and target update in the UpdatePath coroutine?

RobertFriedJ
Автор

in this game can we make a camera keep tracking at player when we move ????

do you have a video to teach this tips i follow you to ep 6 now ^ ^

thx anyways

thebank