Why is my enemy sprite not flipping_v

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Spafnar

I have a RigidBody2D Node called fireball that will be spawning from bottom of the stage and shooting up. It has a gravity scale of 1.7 and I planned on it falling back down and flipping the sprite with it. The code so far is very simple, however, running early tests in the fireball scene doesn’t have it flipping the fireball to show it flying downwards. Here is the code.

extends RigidBody2D

export var min_speed = 400
export var max_speed = 550

func _process(_delta):
var velocity = Vector2.ZERO
$Sprite.flip_v = velocity.y < 0

Its a fairly simple code but it doesn’t seem to be working, can anyone help me. I’ve also tried .y > 0 because I can never remember which direction is which for up and down.

In Godot negative y axis is towards above. So when your fireball goes up, it’s y value must be decreasing. But the thing here is, are you sure it’s value goes in negative ? Maybe you placed fireball at a location where it’s y value becomes less as it goes up and more as it comes down but never becomes negative. Just my speculation

Scavex | 2021-02-01 18:33

I think that might be the case. After I changed the equation to

$Sprite.flip_v = velocity.y > -1

as well as

$Sprite.flip_v = velocity.y < 1

The fireball would come up upside down instead, and not flip upright. How would I fix the thing you’re describing where its y value only goes less but never negative?

Spafnar | 2021-02-03 17:45

I might be mistaken here, but it looks to me like you are setting velocity to Vector2.ZERO, which equals (0,0).
Then, velocity.y is not less than or greater than 0, so the flip_v value would never change.
Maybe try using linear_velocity instead of a zero vector?

Death of Shadows | 2021-02-05 13:24