Might be straight forward answers but haven’t been able to find them. First problem trying to solve is for a TD game similar to plant vs zombies. I’m trying to make it so a projectile doesn’t knock back a certain enemy when they are in a jumping state.
Im wanting if they are in the animation state but the if statement is never called and returns an error message saying trying to find an animation that isn’t there, Tried searching for ways of finding the animation with Animator but cant find any methods with Animator for that.
Also trying to get it so the enemy that can jump over a rock to not go past the first tower behind the rock. I’ve been trying several methods and now trying to get the fox to land using code but isn’t landing accurately. Code below.
You can use Animator.GetCurrentAnimatorStateInfo(0).fullPathHash== Animator.StringToHash(“jump”),
but it would probably be a better idea to see if the fox is jumping by either checking the animation parameter that decides if its jumping or not with Animator.GetParameter(…) or having the logic inside the fox class tell you itself.
I’m not quite sure what you’re asking for the second problem, but I think you mean the fox is landing at a random distance each time. Make sure you’re taking delta time into account. You could also try using MoveTowards, or Lerp.
Hi Zee_pso thanks for the reply.I’m struggling to make sense of how what you’ve suggested works as they are new concepts to me.
I’ve looked in the unity docs can’t make sense of how stringtohash or what fullpathhash does? I don’t understand hash values themselves either.
Also what does the GetCurrentAnimatorStateInfo(0) do why is there a 0. I know I’m asking alot of questions, the unity docs are really lacking in some areas.
The second problem is basically making it so the fox accurately lands between the wall that it has jumped over and the tower behind the wall. Will look further into movetowards and lerp.
The method asks for the the animation layer, and 0 is usually the base layer. If you only have one layer, just use 0. In simple terms, you’re just comparing one path to another. You can pretend the code is Ani.getCurrentPath() == “myPath”. It’s just Unity goes through a hashing function to do so, but you don’t need to worry about how hashing works to use it.
I forgot to mention, you also need to add the layer name(s) to the string to hash function, so it would be Animator.StringToHash(“Base Layer.jump”) if you’re on the base layer (check the upper left hand side of the animator window to see the path. Also, jump is the name of the state, not the animation.
If for example, you’re in a state machine, you’d need Animator.StringToHash(“Base Layer.jumpingState.jump”), and in the upper left hand side, you’d see base layer > jumpingstate in the tool bar.
I would try using something like the following code for testing purposes: