Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by crowley91t · Mar 20, 2013 at 04:52 PM · c#javascriptaizombie

looking to make for a zombie script AI,navmesh or not?

Hi i m looking to make a simple zombie script AI. The enemy should follow "player" and when the distance of player and enemy is near, this attack changing the animation

To make a good zombie script i need a navmesh agent or not? can you help me with a simple start code?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ROLLERROCK · Mar 16, 2015 at 11:13 AM 0
Share

i would suggest against navmesh as zombies are not expected to be smart. and a zombie that can make its way through mazes without even seeing the player wouldn't make sense

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by deltamish · Mar 22, 2013 at 07:02 AM

hi

here is a simple AI code that moves th character without using character controller or Navmesh

Edit

 #pragma strict
 
 var Attackdist:float = 5;
  
 var Player:Transform;
  
 var MoveAnim:AnimationClip;
 var AttackAnim:AnimationClip;
 var speed:float;
  
 var damage:float = 5;
  var model:Transform;
 private var _me:Transform;///this the character
 private var tempspeed:float;
 function Start(){
 tempspeed = speed;
 if(!_me)
 _me = transform;//cache for better performance
 model.animation[MoveAnim.name].wrapMode = WrapMode.Loop;
 model.animation[AttackAnim.name].wrapMode = WrapMode.Once;
 }
  
 function Update(){
 //transform.LookAt(Player);
 _me.rotation = Quaternion.Slerp(_me.rotation,Quaternion.LookRotation(Player.position - _me.position),Time.deltaTime * 9);
 _me.eulerAngles = Vector3(0,_me.eulerAngles.y,0);
 var fwd:Vector3 = _me.TransformDirection(0,0,1);
 transform.position += fwd*speed*Time.deltaTime;
 
 model.animation.Play(MoveAnim.name);
 if(Vector3.Distance(_me.position,Player.position) <=Attackdist){
 speed = 0;
 Attack();
 }else{
 model.animation[AttackAnim.name].layer = -1;///add this if not it will not play move anim
 speed = tempspeed; //initial speed
 }
 }
  
 function Attack(){
 //yield WaitForSeconds(0.5);//wait 0.5 seconds before playing anim
 if(!model.animation.IsPlaying(AttackAnim.name))
 model.animation[AttackAnim.name].layer = 1;//add this if not it will not play attack animation
 model.animation.Play(AttackAnim.name);
 Player.SendMessage("TakeDamage",damage,SendMessageOptions.DontRequireReceiver);
 }



 
Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image crowley91t · Mar 22, 2013 at 01:43 PM 0
Share

Hi deltamish.

Your script it is very good and work perfectly.

But only on one model of zombie, this script don't work.

When the game start, this zombie follow the player but the animation of zombie model rotate model.

sorry for my bad english

see my video to understand my problem.
http://youtu.be/GU6JkzNPpPg

What differences are there between navmesh and character controller?

Thank you very much for your help.

avatar image deltamish · Mar 23, 2013 at 06:07 AM 1
Share

hi Thats pretty strange,, you can fix this by Removing rotation from the animation of the model (did you animate it your self)

and your english isnt that bad

Can you upload your model so that i can see the problem

PS.By the i observed you were using Unity 4 i am using unity 3.5.6 i am planning to upgrade it for a long time but i fear the upgrading may taking a long time and i read somewhere in unity Answers that some projects were ruined after upgrading to unity 4 i dont know if thats true so do you think upgrading to unity 4 is worth it and is there realtime reflection in unity 4(I think i read this somwhere)

avatar image crowley91t · Mar 23, 2013 at 12:42 PM 0
Share

Hi deltamish.

how to Remove rotation from the animation?

i have upload the free model (downloaded on the web, it is free) on my google drive

Link : https://docs.google.com

I'm using Unity 4 from a few months and my projects work perfectly, and i don t use realtime reflection.

Thank you very much for your help!!

avatar image deltamish · Mar 23, 2013 at 02:53 PM 1
Share

hi i got the files i will try to fix it now and by the way did you create all that animation and textures

Really nice

avatar image deltamish · Mar 23, 2013 at 03:58 PM 1
Share

hi found out the problem the problem was the forward of the model is actually right of the model that means the front(facial) part of the model is not forward(blue coloured arrow) in its local or world axis its is right(red color arrow) so all you have to do is create a new empty gameobject and rotate in such a way that the facial part of the model and the forward(blue arrow) of the empty gameobject face same direction then make the zombie object child of empty object

and if you want even more realistic animation(animation spedd very very important) just lerp from 0 to speed and divide

Show more comments
avatar image
1

Answer by Omir · Mar 20, 2013 at 06:06 PM

If You are beginner believe me brother AI is most worst thing is game Development , no one here will help you with this stuff ... You Search for Term A* algorithm and get started but i will prefer to you to use a plugin known as "RAIN AI" Best part of plugin is its free and it support zombies comes with video tutorials by both RAIN and Tornado Twins Cheers here is the Link RAIN AI : http://rivaltheory.com/tag/rain-ai Grab your free copy now .. !!! Happy AI

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Ai Zombie Melee Attack script. 5 Answers

AI controller script, Enemy movement issues 0 Answers

Javascript not being updated, variables being overridden, but C# is fine 1 Answer

js source file has been changed to created in cs. 1 Answer

How to get faster script compilation? 6 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges