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 /
avatar image
0
Question by ApolloVision · Mar 04, 2014 at 02:42 PM · animationjavascriptprogrammingbeginner

In-depth Animation and Audio guide for Enemy AI?

Hello,

In my game I currently have a playing field with obstacles, a playable Player that can melee(Raycast) and shoot(collision-based) and an Enemy AI with Astar AI system that can detect obstacles and does pathfinding on its own, the AI also wanders around the scene at random direction and then follows the player when spotted.

Both the Player and Enemy are just Capsules. I used a program called Makehuman which allows you to create realistic human bodies and export it to Unity with a rig already attached, so I can now start animating straight away.

I know how to animate and script Humans (eg. Walk/Run animation when pressing W, A, S or D, etc). But Enemy AI that does not press buttons? I don't know... Is there any good tutorial series that will help me exactly how to implement animations into players/AI? I'd prefer a video series since when I read documentation for Blender and Unity I just fell asleep, I am not really into programming but this is for my software school project which tells us to make a game.

Also as a bonus question. I currently applied footstep audio and shooting audio to my Player whenever the Player presses Input buttons that they could horizontally or vertically move then the footstep audio will automatically play and loops or whenever the presses the Left Mouse button (Fire1) the shoot audio also plays. But how do you apply that to Enemy which does not have an Input? How do I say: if Enemy moves Horizontal or Vertical -> Play Audio or if Enemy shoot/melee -> Play Audio?

Here is my Javascript for the Player Audio which works absolutely fine:

 var footsteps : AudioClip;
   
 function Start() 
 {
    audio.clip = footsteps;
     audio.loop = true;
 }
 
 function Update()
 {
 
   // If a movement button has been pressed, play sound
    if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
     {
 
        // Only start playing, if the audio hasn't been started yet
 
       if(!audio.isPlaying)
           audio.Play();
    }
 
    // If none of the movement buttons is pressed, stop sound
     if(Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0){
        audio.Stop();

How do I translate that to Enemy AI? I am a beginner when it comes to programming, but as a game modder I do understand Javascripts/CS but writing from scratch? Not so sure. Thank you.

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 ApolloVision · Mar 19, 2014 at 06:48 AM 0
Share

No answers?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Cherno · Mar 19, 2014 at 12:25 PM

Ther eis no easy way about it. AI is one of the most complex fields in programming, but if you start simple you can achieve some basic behavior. The AI doesn't have keyboard input, so it has to have some sort of decision-making process of what to do in any given situation. Give it a state of "idle", for example, and then just randomly determine a position around it and make it move towards it. This requires a pathfinding algorithm to check if it can actually move there, and then it could just use the same movement function the player uses. I recommend AngryAnts A* Pathfinding project, it'S free and fairly powerful. Gernerally, you want to share as many functions as possible between the player and AI characters.

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

21 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

How would you reccommend adding the jumping animation to my script? 0 Answers

Is this a good source to learn javascript? 1 Answer

How to approach different game modes 2 Answers

Play a simple animation once on key press 3 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