Hi. Suppose we have some logical states (chase,move to a random checkpoint etc) and have some animation states (idle,run,walk,crouch).
we know you can be in chase state and also run/walk/crouch or for move to a random checkpoint etc
Is it better to separate them from each other?
mechanim for animation states and state machine design pattern for logical states?
public class CChase:IState{
public void Start(){
}
public void Update(){
if(...){
// animator.setFloat("",);
}
else{
// animator.setFloat("",);
}
}
public void Exit(){
}
}
Mechanim is a state machine and some people use it for general ai:
However, I am still a little wary of it because it was actually created for animation states. I’m still up in the air on it, though. There are examples on youtube, but they seem pretty simplistic. I think it would require breaking the code down into smaller blocks and might make it overly complicated.
I might do a tutorial on it and play with it to see if it would be useful enough.
So you say create all states in mechanim?! (chase,move to a random checkpoint etc (that are logical) and run/walk/crouch (that are animations))
Yeah, you can because there is a StateMachineBehaviour class in Unity that will show up in Mecanim, so you can do logic with it.
https://unity3d.com/learn/tutorials/modules/beginner/5-pre-order-beta/state-machine-behaviours
That’s my understanding of it, but I haven’t had time to really check it out.
I know state machine behaviour but I think you didn’t know my question
“we know you can be in chase state and also run/walk/crouch or for move to a random checkpoint etc”
they are independent so needs to create two separate state machines
Yes, I’m just saying they could be combined by using mecanim for logic. Animations, though, are really separate things, like sound effects or something. They are only states in a smaller sense. Your code would be a mess if walking was a state. I wouldn’t treat them as a state myself. You might walk while patrolling, but that’s a very small part of the logic. The real logic is moving between destinations and wating for other input. They are closely linked though. Usually you walk while patrolling, but chasing might involve hiding behind objects, occasional shooting, etc. Some people like to break it down to it’s smallest part, but there has to be some motive for walking. I think you would almost need substates, also. Like stopping to shoot while chasing would be a substate. When finished you might look for other cover, or direct chase, or whatever, but I don’t think it would ever get down to just walking myself because it is always connected to a larger motivation.
1 Like