0 votes

I recently wrote a code that would allow a fireball to shoot out from the bottom of the playerview, and then would be affected by gravity and fly back downwards. The purpose of the code had to do with flipping v, and ultimately the code had to check for the global position instead of the velocity. This is the code:

var direction = "up"
var lastpos = globalposition.y

func _process(_delta):
if last_pos < global_position.y:
    last_pos = global_position.y
    direction = "down"
elif last_pos > global_position.y:
    last_pos = global_position.y
    direction = "up"
match direction:
        $Sprite.flip_v = false
        $Sprite.flip_v = true

I was happy to see it finally flipping like I wanted to, but after closing the debuger I noticed there was a large amount of errors in my debug menu. It was as follows:

"getglobaltransform: Condition "!isinsidetree()" is true. Returned: get_transform()"

There was 26 of them and I'm guessing that number comes from how many fireballs I allowed to spawn. Does anyone know what this error does or is, and if it affects anything.

Godot version 3.2.3
in Engine by (53 points)
edited by

1 Answer

0 votes

It seems like you forgot to call add_child() after you instanced the fireball. Does it have a parent?

by (35 points)

The script for instancing the fireball in the main scene is as follows:

    var ball_spawn_location = $ChomperPath/ChomperSpawnLocation
ball_spawn_location.offset = randi()

var ball = Fireball.instance()

var direction = $ChomperPath/ChomperSpawnLocation.rotation + PI/2
ball.position = ball_spawn_location.position

var velocity = Vector2(rand_range(ball.min_speed, ball.max_speed), 0)
ball.linear_velocity = velocity.rotated(direction)
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.