- Edited
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