So I’m trying to make a moving scriptand I’m trying to flip the characters sprite but the thing keeps reverting back to its first value
Context: I have a condition if velocity.x <= 0.0 it flips and vice versa but it keeps reverting back to its original value because the thing only turns into that value while velocity.x <= 0.0
Is there a way i can fix this and flip the charcter while keeping the value the same (also sorry for my bad writing im In a rush)
I don’t fully understand your problem. But if your problem is: “if my character moves to the left and then comes to a full stop, the character’s sprite flips to face the wrong way”, then that’s explained by your code.
If velocity.x equals 0.0 exactly, then both if statements are true. The sprite’s flip_h property will first be set to true, and then on the same frame it will be set to false.
Consider using the last input direction to figure out which way the sprite should face instead of the character’s current velocity.
This way, the conditions don’t conflict because instead of using >=, we used > only. So the character should stay at the last flip_h state when it comes to a stop. Also used elif, because if velocity is lower than zero, you don’t need to check it again for the second condition.
One more thing, 0 tends to be unreliable for a check condition because of floating point errors, so if you still encounter flip issues, you can change the conditions to this
if velocity.x < -0.01:
...
elif velocity.x > 0.01:
...