I’ve been working on this for far too long and my brain has turned to mush. I’m trying to get my player character to “turn around” (animation only) before switching direction
I have done this by adding a Turn_around_state in my finite state machine but now i it won’t change states (it did before without the direction.x != 0)
# if player direction is not the same as the previous direction they were facing and it's not 0 (standing still currently)
# then switch states to turn state
if character.latest_direction != direction.x and direction.x != 0:
playback.travel(Turn_node)
next_state = Turn_state
Please ask if you have any questions or if you need to see any more code, node setup or animation tree node setup
They are not identical no. Latest direction is a variable I have used for other stuff but I came in handy here. My thought process is that when both direction.x and latest_direction are updating simultaneously they will only be different from each other the moment the player character stops moving in one direction and starts moving in the opposite (or when he stops moving and stands still, hence the direction.x != 0)
Sometimes it’s best to just print values and see what’s happening, but I can see potential failure modes here depending on how latest_direction and direction.x get set.
At the worst, if latest_direction can vary (say, because of an analog stick) you might actually be constantly retriggering the inside of that if block.
I’ve changed the latest_direction variable to a local variable now (the way it was used before was messing it up) But now i need to figure out how to call it so it triggers the turn around state
as well as possibly a reset for the new latest direction variable when reentering the run state