- Home /
Creating a fighting system with mecanim
So i have been working with Mecanim to create my own character controller, I have the basic movement down to a t, but im having trouble trying to create a simple fighting system with 4 main animations; kick 1/kick2/punch1/punch2.
I want to create a simple blend tree that will blend the animations if and when they are pressed within seconds of each other. But how should this be set up?
Should I add 4 Bool's in the parameter box (each of the animation motions) and have this called upon similiar to the jump feature in the Mecanim Tute? Or am i trying to make something more complicated than it needs to be?
I have this line of code to activate the move(s), I copied and pasted with minor changes for every other animation file. I tried this out with my 4 Bool parameters in place and gave it a transition too and from the locomotion blend tree and the idle state but it didnt play the animations I was trying to activate with the corresponding keys.
if(Input.GetButtonDown("O")){ animator.SetBool("Punch1", true );}
I have basically followed the steps of the main Mecanim Tute (the 40min video on youtube) so my characters animator is layed out exactly like that using the BotCntrl script which i have modified with 4 lines of code, like the example above.
any help/advice what so ever would be greatly appreciated
Answer by Itinerant · Jan 08, 2013 at 05:23 PM
Hmm, I've never tried to do this before, but my thought would be to have an int, rather than a boolean. Then on button press, have a function that adds one to that int, yields for a second or two, then subtracts one. That way you can test for multiple presses of the same button, like 'up up up.'
Actually, that might not be the best way, because that won't let you order things. Maybe have an array of key presses as strings? Again you call a function, it adds the key to the end of the array, waits a set number of seconds, then removes it. You check the array on each key press, and if it matches any one of a number of preset combinations, you do your combo move.
Sounds like a fun thing to do.
hmm, ok im not too familiar with Arrays and how they work so maybe i should start with something simpler i.e a script that triggers the various animations with the different key presses, then add an array as you said. thanks
Answer by cgjerry87 · Apr 22, 2014 at 08:26 PM
Something that it came to me is: having an int represents each botton key. Then an int array which reads when keys are pressed and finally use cases on int combinations of the int array, to have the corresponding movement. (Also when it reads the array having a time delay between each stroke to read next or start from zero) so it doesn't reads previous keystrokes if time passed.Needs a time offset. Since u r using mechanim it reads input data of axis or any input so this is great for continues movement to blend combos
Answer by andyspeak · May 05, 2014 at 10:51 AM
you should look into mecanim trigger its like a bool but it auto resets when you use it so you could do on button down activate trigger and then keep taping to keep the trigger active and have the animation on a exit time so if you dont get a trigger it will go back to idle of wat u want
https://docs.unity3d.com/Documentation/ScriptReference/Animator.SetTrigger.html link to trigger doc
but my problem is timeing the animtatin for an even like i set waitForEndFrame so it has time to change the animation then yeild wait animation length or what u need the active event but timing it is hard lol i am goin to try a time.deltatime when i get home
u can also use the yeild return wait animeation.length /2 and add a gleam partical effect for the combo activation so u know when to tap and add bouns
and retern new 1 //is num frames 0 is 1 lol
will give the animation time to change its only like 0.04secs so u wont see it but is you call event to soon it will use the length of the animation before and the ti$$anonymous$$g will be off
p.s i use c# its alot stricter so easy to mes up but cleaner code
Answer by dudedude123 · May 22, 2014 at 07:53 PM
I have it taken care of in my video
But if you prefer button mashing
if (Input.GetButtonUp("Punch"))
{
animator.SetBool("punch", true);
}
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Turning to face movement direction 0 Answers
unexpected movement with mecanim 0 Answers
Multiple movement modes in mecanim 0 Answers
Basic animation key press 0 Answers