Skip to main content

007. Unity3d Tutorial - Melee Combat 3/3

See video

This is the third part of a 3 part mini. This set of tutorials will have us setting up a basic melee combat system for our little hack and slash game made with the unity game engine.

Tags:

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Offline
Joined: Nov 19 2010

Hi, fantastic tutorials. Thank you soo much for your time!

So far it has been great, and you do explain things well, indeed I am a bit surprised I have this problem because so far everything is logical and easy to understand.

After completing this Melee Combat 3/3 my enemy moves towards me but it does not stop at distance 2, he comes all the way to the position of my player and spins. I checked my code and it does match yours and it should do what it should do but the enemy does not stop, almost like if the changes in part 3/3 didn't really make any difference. Unity3.1 Pro

Any idea?
Thanks

Offline
Joined: Nov 19 2010

Sorted :)
please feel free to delete my comment above, issue not really an issue anymore :)

Petey's picture
Offline
Joined: Feb 3 2010

Instead of me deleting the post, can you tell us what the problem was? This may help others that get the same problem.

Offline
Joined: Nov 19 2010

oh I didn't post the solution because it was totally my fault. it was late night early morning and I thought it could have been some punctuation mistake e.g. a non required ';' or a missing one. But my eyes must have been tired because I kept reading my code and it appeared to be ok... then a little bit fresher today I went through the code again and there it was, a ';' where it was not required. Funny enough I spent time adding debugging lines to follow changes in distance etc... all it was, was a wrong ';' added by mistake after this line: if(Vector3.Distance(target.position, myTransform.position) > maxDistance) or after a method round brakets... can't remember exactly.

Offline
Joined: Dec 12 2010

Hey! I really like your tutorials, I found them very inspirating and I learn a lot from them!

But now I have a problem. I am working on an RPG, and I combined the EnemyAI script with the enemy atack one. I also modified it a bit, the way I wanted it to be. Here's where the problem is. When I try to run the game, I get an "Object reference not set to an instance of an object" error. It takes me to this line: targetHealth.AdjustCurrentHealth(-enemyAtackDamage);

Here's my atack function:

private void Atack(){
sPlayerGUI targetHealth = (sPlayerGUI)target.GetComponent("sPlayerGUI");
targetHealth.AdjustCurrentHealth(-enemyAtackDamage);
}

I looked up at every piece of code, but I dont understand it.

I would really apreciate your help.
I cant show the full scripts here but if you want to help me and take a look at them, mail me at m3llyXProductions@gmail.com

Thanks a lot

~~Andrew

Offline
Joined: Dec 23 2010

I get this error in the enemyattack

NullReferenceException: Object reference not set to an instance of an object
EnemyAttack.Attack () (at Assets/Scripts/EnemyAttack.cs:50)
EnemyAttack.Update () (at Assets/Scripts/EnemyAttack.cs:26)

I don't know what can be wrong because the player attack works fine and the scripts enemy/player health are the same only with the GUI position diferent and enemy/player attack have only different the keyboard input and the script name for the component thing.

eh.AdjustCurrentHealth(-10); is line 50

if(distance < 2.5f){
if(direction > 0){
PlayerHealth eh = (PlayerHealth)target.GetComponent("PlayerHealth");
eh.AdjustCurrentHealth(-10);
}
}

Petey's picture
Offline
Joined: Feb 3 2010

All of the scripts for the first ten tutorials are available for free from the educational section of the site. You can find them here:
http://www.burgzergarcade.com/educational/educational/free-tutorials/hac...

Offline
Joined: Dec 23 2010

nice... i've seen the error ... to ashamed to tell it Q.Q cough "addjust instead of adjust" in playerhealth cough

Petey's picture
Offline
Joined: Feb 3 2010

Glad to hear you found it.