Hello everyone,

I need to make a plane to fly. I use a 2D scene. The plane has to go from A -> B -> C. When the plane reach B,
it must go to C but his sprite must show to the player it turns to the left or right, depending on the direction.

I will share you below the code "frame manager", the plane's rotation sprite and the plane's fly sprite. When the plane must turn to the opposite direction, i activate the H-flip to make that "logic".

The direction is a vector2: (-46, 21) as velocity, but somewhere to (-1, 1) so (-50, 50).

From B -> C, the plane must turn and the H-flip must be activated. The code give me as result the frame 7, but i need the frame 2.
When the rotation frame reached, the animated sprite must have the fly framesheet and the correct frame must be the frame 7.

So that's means the result give me the correct visual frame for the fly state, but not for the turn state as no H-flip. That's why i must activate the H-flip, but because the H-flip is activated, the visuel correct frame isn't 7 but must be 2.

So, what should i modifiy in the code when the plane must use the turn spritesheet whith H-flip activated ?

If something isn't clear, please let me know it.
Thank you.

fly spritesheet

turn spritesheet

# chassis = animated sprite node
velocity = velocity.round()
var oldDeg = rad2deg(oldAngle.angle())
var angleToDeg = rad2deg(velocity.angle())

var angleDestination = wrapf(angleToDeg, 0, 360)

newFrame = round(angleDestination/22.5) # 360 / 16 frames

if newFrame == 16:
	newFrame = 0

var diffAngl = angleDestination - oldDeg
			
if diffAngl > 180:
	diffAngl -= 360
elif diffAngl < -180:
	diffAngl += 360
				
if diffAngl < 0:
	chassis.flip_h = true
else:
	chassis.flip_h = false
			
if chassis.frame != newFrame:
	 if diffAngl < 0:
		chassis.play("", true)
	 else:
		chassis.play()
else:
	chassis.play("airReconTurn")
	# moving
  • xyz replied to this.
  • I found what's wrong. It's not the spritesheet, it's the h-flip, it was a trap.

    I must make two turn spritesheet, one where the plane rotate to the left, another to the right. After, i forget to take care when i change a sprite dynamically: the frame reset to zero when the animation change. So if the plane goes straight on, and he has the current frame 7, when it must turn, it fall to 0, so i have to update the frame in the same time i change the spritesheet (animation).

    After that, the algorythm must find if he should play the spritesheet in reverse or not + the direction (left or right).

    Problem solved.

    Thank you to be here and your time.

    TwistedMind Use only one sprite sheet with full 360 deg turn.

    In this case, i need to give more precisions:

    The scene "vehicle" share the land, sea and air type, the code too. The land and sea aren't need any rotations, it's like the fly spritesheet, so 16 frames.

    That's why i'm looking for a solution to not make unnecessary scene items.

    • xyz replied to this.

      TwistedMind Use one sheet with full 360 turn but with variable number of frames. So if an unit has to have more granulated turning animation, just use more frames. Otherwise use less frames. You can easily extract 16 directions from any sheet that has multiple of 16 frames. Your current systems sounds too complicated.

      I found what's wrong. It's not the spritesheet, it's the h-flip, it was a trap.

      I must make two turn spritesheet, one where the plane rotate to the left, another to the right. After, i forget to take care when i change a sprite dynamically: the frame reset to zero when the animation change. So if the plane goes straight on, and he has the current frame 7, when it must turn, it fall to 0, so i have to update the frame in the same time i change the spritesheet (animation).

      After that, the algorythm must find if he should play the spritesheet in reverse or not + the direction (left or right).

      Problem solved.

      Thank you to be here and your time.