I would like to simply write my controller script to for example “on key press” “trigger single animation”. Every guide only shows how to use floats and animation pools.
I see there is an int option in parameters, but how do i assign an animation to an int. if i wanted walk to be int 1 for example. Or is this done with “tags”?
It just seems easier for me to trigger an animation by assigned integer or even tag.
I have spent the last 3 days learning about animations but everything is based on floats.
The only time I have been able to simply assign an integer to an animation is by using the pool, if i do not have a pool i see now options to assign anything to it, but i heard you could also trigger the animation by using “tag”?
Sorry i just want to be able to move onto other things learning wise, and have been stuck on animations for a week.
I just want to simply have
w = walk
shift + w = run
mouse click = slash with weapon
should be easy but it is giving me problems. <3
So if anyone could easily and briefly explain how i would simply tell mecanim to play the walk animation while w is held down, it would be a huge help since i do not see a need to create a pool for every animation, i just do not see a way to give them an identifier, and how to activate them by simply activating them by said identifier on said key press. lol
How many states do you have, and what do your transitions look like?
just 3 states right now for learning. idle which works as default, walk and run. I have basic transitions set up but im not worried about that right now, i just want to find a way to activate states i want via key press, i know about the pool method using floats to switch states based on speed. I do not want to run every time based on speed, i plan on adding stamina system so i want the controls set up to use shift to run. Just not sure how to do it, another thing i am unsure of is how people use “vertical” and “horizontal” and unity just automatically uses wasd without being told to.
Not completely sure what you’re asking. Are you using the example of Animator.SetFloat()? Because, Animator has a SetBool() for boolean (on/off) parameters, and SetInteger() which is what you may want. I typically use SetTrigger() though, since that’s like the most basic method to trigger transitions.
hmmmm, what i am unsure of is, lets say i have animation state idle and walk, in the animator i see no option in the panel to assign anything to it for calling in the player control script, though a guide did say the name and tag at the top in the state’s inspector could be set, and use to call it. So my main issue is i am unsure how to even reference a state in a control script unless you have a float set up using decimals.
Trigger sounds more like what i am looking for to be honest. I suppose i just need to keep digging, i made sure to go through unity’s tutorials before asking questions in order to not waste anyone’s time. Still every guide i see just uses the same float trick, and does not demonstrate the use of ints and triggers.
Simply, all i want to do for learning purposes, is press w, by using onkeypress instead of getaxis vertical, I insist on wanting to manually detect the keypress of w on update, triggering the state of walk. Should not be this hard. 
Take a look at this tutorial (https://unity3d.com/learn/tutorials/projects/2d-roguelike/player-animator?playlist=17150) and see if it’s what you want. It’s hidden in the 2D tutorial, but I think it’s a really good intro to Unity animation. Hope this is what you’re looking for.
EDIT:
That video doesn’t have any scripting in it though. Pseudocode would look something like
if (Input.GetKeyDown('W'))
{
animator.SetTrigger("nameOfTriggerParameter");
}
thank you, what i am unsure of is where to set nameoftriggerparameter since the only time i saw anything close was setting up integers in a pool, than triggering. Thanks again.
I will get it figured out and that script looks very straight forward, what i was looking for. Thank you again, going to continue to put in the effort to get this figured out. <3
EDIT: This video is perfect, I get it now. What i did not understand was how the trigger parameter knew what animation it was connected to, now i see those settings are set by creating transitions.
\m/ <3
1 Like
I’m actually still not sure where you’re getting the pool idea from. This doesn’t really require any pools of anything. The parameter is added in the Animator Window, under the parameters tab, as in the tutorial video that I linked to. The name of that parameter is the name that you would use as “nameOfTriggerParameter”.
Okay so it is working but not as planned. When I press W i walk, but when i let go of W i continue to walk, and there is no way to go back to idle.
So is trigger not the right way to go about a typical WASD type of game?
EDIT: Also when i walk down a hill, i do not walk down the hill i walk in the air same level. been googling but am unsure which setting would cause me to not scale down elevations. hmmmph
EDIT2: I added rigidbody to the character for gravity and it did not work… lol
EDIT3: I think it is just the scene’s terrain, it is a demo terrain from an asset pack i purchased, when i created blank scene with blank terrain and added rigidbody to cube gravity worked. Sorry for asking questions without doing full research. 
You’d have to appropriately set up a transition from walk to idle to listen to another trigger, say “stopWalking”, and look for a GetKeyUp(‘W’). This will then trigger the transition back to idle.
yes i was just thinking about that on my drive, if there is a getkeyup function i could transition it back to idle, and you just verified that there is one. I like to work smarter not harder, i spent two years planning this project so i wouldn’t just be sitting in the editor wasting coding hours. Will the trigger method using both key up and key down be practical for a typical WASD movement game? Am i going to spend more energy configuring keyup counter states than if i used another method? Trying to think about the grand scheme.
Though i suppose if i spent less time contemplating the appropriate course to take, and more time in the editor making it so i could be on to the next thing, so for now i will just use trigger and get it done so i can move on to the next thing maybe ahead of schedule “i gave myself til the 1st of april to complete version 1 of my rigging.”
Okay so i have pretty much all my movements animations rigged, i am working on my control script. Question is:
Is there an operation to check if a trigger is active? I know there is SetTrigger, but i need a GetTrigger and it does not seem to exist.
I tried to listen for both shift being pressed and W to activate sprint, but it does not work, here is my code.
if(Input.GetKeyDown(KeyCode.W))
{
anim.SetTrigger(“walk”);
}
if(Input.GetKeyUp(KeyCode.W))
{
anim.SetTrigger(“idle”);
}
if(Input.GetKeyUp(KeyCode.LeftShift)&&Input.GetKeyDown(KeyCode.W))
{
anim.SetTrigger(“walk”);
}
if(Input.GetKeyDown(KeyCode.W)&&Input.GetKeyDown(KeyCode.LeftShift))
{
anim.SetTrigger(“run”);
}
EDIT: The script for both keys pressed together to sprint does work, but you have to press them at exactly the same time, so for sprinting i need to do a check to to see if walk trigger is active. I know you can getbool but does getbool work if you are using a trigger instead of a bool?