Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Jack Eaves · May 05, 2010 at 08:42 PM · javascriptaicombat

Character AI for fightscene

Hi there,

I am trying to create a scene in my game where you fight a big monster. I want the monster to use random moves against you such as a standard attack (sword swipe) and a special move (tail swing). It would also be good if he would get within range to attack so that he could make contact with you instead of just swiping in your direction even if you are 10 meters away.

I really havn't got a clue of how i will achieve this so any help would be very appreciated.

I am also interested in having a trigger activate once the boss has got to a certain percentage of health - though that might be best answered if i make a new question.

Thanks!

Comment
Add comment
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

1 Reply

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

Answer by Azrael · May 05, 2010 at 10:01 PM

Hmm it seems to me what you need is a coroutine and some animation events. thats the easiest way to do this.

just call a function like this once

var WaitTime:int=10 // betweenattacks

function monsterAttack(){ while (true){ do_attack(1); yield waitforseconds(WaitTime); do_attack(2); yield waitforseconds(WaitTime); do_attack(3); yield waitforseconds(WaitTime); } }

in the function do_attack(attack) simply activate the animation that corresponds to that attack you can attach an animation event to the attack animation frame you'd like and assign how much damage it makes (if the character is not blocking)

For the AI apply a series of conditions for each attack per example check the distance of the hero, or how much health he (she) has, to use attack 1 , 2 or 3 to check the distance, simply create a vector between the AI character and the player and check its magnitude.

Per example

    while (true){
    var distance:Vector3=(Player1.transform.position-Enemy.transform.position);
var dis:float=distance.magnitude;
    if (dis<100) do_attack(1) else do_attack(2);
    yield waitForSeconds(WaitTime);
    }

Comment
Add comment · Show 5 · 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 Jack Eaves · May 06, 2010 at 06:13 AM 0
Share

Thank you Azrael$$anonymous$$! I'll give this a shot - though looking at it seems to look like a good solution.

avatar image Jack Eaves · May 06, 2010 at 08:49 AM 0
Share

I have just created a Javascript with this script and it doesn't seem to work, at first i get an error saying that a ';' needs to be placed at (1,20) after the Var WaitTime:int=10.

However once i insert the ';' i then continue to get errors saying that 'int' is an unkown identifier, 'wait for seconds' is an unknown identifier.. and more, maybe i am doing something wrong.

avatar image Azrael · May 07, 2010 at 08:31 PM 0
Share

Oh sorry the code I supplied is just an example, yes Im missing a ";" int should be recognized in javascript and waitforseconds must have capital letters like this "WaitForSeconds()"

avatar image Jack Eaves · May 14, 2010 at 09:26 AM 0
Share

Thank you i'll try it again =)

avatar image Jack Eaves · May 14, 2010 at 09:58 AM 0
Share

Still having problems, i'll open a new question. Thanks for the help s far though!

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

No one has followed this question yet.

Related Questions

AI navigating all 6 sides of a cube 0 Answers

How I can make a simple follow AI in Unity 5? 1 Answer

AI controller script, Enemy movement issues 0 Answers

Ai finding target after spawning 2 Answers

array of boxes 2 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