0 votes

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 minspeed = 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.

Godot version 3.2.3
in Engine by (53 points)

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

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?

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 flipv value would never change.
Maybe try using linear
velocity instead of a zero vector?

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.