0
Friends I’m messing with the jumping animation of a character and this animation has two sequences, one of when walking, the other running:
if (Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.LeftShift))
{
heroiRB.AddForce(new Vector2(0, force), ForceMode2D.Impulse);
PuloLateral();
}
else if (Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.LeftShift))
{
heroiRB.AddForce(new Vector2(0, force), ForceMode2D.Impulse);
PuloLateral();
}
else if (Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.D))
{
heroiRB.AddForce(new Vector2(0, force), ForceMode2D.Impulse);
anim.SetBool("PuloLateral", true);
anim.SetBool("Andar", false);
}
else if (Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.A))
{
heroiRB.AddForce(new Vector2(0, force), ForceMode2D.Impulse);
anim.SetBool("PuloLateral", true);
anim.SetBool("Andar", false);
}
I wanted to create a void Pulolateral(){} method to make it more organized, but I found a certain difficulty in trying this, since it has two sequences, running and walking. Is it possible to leave these two sequences in the same Pulolateral() method? I tried with an If test and could not get the result, just the running jump works:
void PuloLateral()
{
if (Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.LeftShift) || (Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.LeftShift)))
{
anim.SetBool("PuloLateral", true);
anim.SetBool("Correr", false);
}
else if (Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.D) || Input.GetKeyDown(KeyCode.Space) && liberaPulo == true && Input.GetKey(KeyCode.A))
{
anim.SetBool("PuloLateral", true);
anim.SetBool("Andar", false);
}
}
What exactly is the problem?
– Leandro Angelo
The problem is that the animation of Pulolateral is not being executed when the character jumps walking, even though everything is right in Animator, so to better organize the animations I wanted to create a method for them. In the case of the Pulolateral method created the way I went, the animation still doesn’t work, I believe there is something wrong with the method that I’m not noticing.
– Raphael
Hello. Have you debugged (debugged)? Are you sure this code is right? I wonder why it seems very strange the method code
PulaLateral
have two conditions that make exactly the same thing (which is to connect the variablePuloLateral
and turn off the variableAndar
).– Luiz Vieira
So Luiz, through the Unity Animator tab, you can see if the action is being executed when you press those keys, and there everything is ok, the strange thing is that it does not execute the animation. Sorry, I don’t know if I got it right but one is transition to Run (walk key + shift pressed) and the other to Walk (no shift). I passed the project to my teacher of the games course and he found it strange not to be running also because it seems to be okay with Animator, said that when you have time will take a better look. I am suspicious of some bug with the engine itself
– Raphael
Hi. It took me a while to answer because you didn’t tag me (with @) in your comment, so I didn’t see it until today. Okay, but I asked if you debugged your code. Is he entering the code you expect him to enter? It’s hard to help you without more specific details. If you make a minimum example that reproduces the problem and climb it somewhere for me to download, I can test and try to help you.
– Luiz Vieira
@Luizvieira Opa Luiz pardon, the studies are running. I had been debugging and I was entering normal just not running anyway, my teacher took a look and really it is a little problem in the version of Unity that I was using (2017.3.1f1) she is with some problems, I downloaded a version of June 2017 and it’s solved, Quarrels for the attention saw!
– Raphael