- Home /
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!
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);
}
Thank you Azrael$$anonymous$$! I'll give this a shot - though looking at it seems to look like a good solution.
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.
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()"
Still having problems, i'll open a new question. Thanks for the help s far though!
Your answer
Follow this Question
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