Godot Version
Godot 4.3
Question
Good morning. I’m developing a Flappy Bird clone. Right now I’m working in the pipes movement, however when I write move_and_slide()
, the objects goes way too fast, even when velocity = 0
I have two scenes pipelines.tscn
(CharacterBody2D) that help me to create pipe, specifying the size, position and the movement behavior.
extends CharacterBody2D
@onready var pipeline_sprite = $PipelineSprite
func _physics_process(delta):
movement()
func create_pipe(x_size, y_size,x_position,y_position):
$PipelineSprite.size.x = x_size
$PipelineSprite.size.y = y_size
$PipelineSprite.position.x = x_position
$PipelineSprite.position.y = y_position
func movement():
velocity.x = 0
move_and_slide()
By the other hand I have Main.tscn
(Node2D), that allowing me to instanstiate the Pipelines.tscn
scene, as many times I need, creating the double pair of pipes with random sizes.
To clarify Pipelines.tscn
is not part of the node tree. Their propeties are call using the instantiate()
method, as you can see in the code bellow.
extends Node2D
var pipe_node = preload("res://Scene/pipelines.tscn")
var screen_max_height = DisplayServer.window_get_size()
func _ready():
spawn_double_pipes(500)
spawn_double_pipes(300)
#spawn_pipes(100,150,500,0)
#spawn_pipes(100,150,300,668)
pass
#Create a pipeline, allowing to specify the size and location.
func spawn_pipes(x_size, y_size, x_position, y_position):
var pipe = pipe_node.instantiate()
pipe.create_pipe(x_size, y_size, x_position, y_position)
add_child(pipe)
#Create a pair of pipeline, from the lower pipeline to the higher one.
func spawn_double_pipes(pipe_location):
var random_height_size = randi() % 668 + 50
var gap = 100
var bottom_size = (screen_max_height.y - random_height_size) - gap
var bottom_height_position = screen_max_height.y - bottom_size
var pipe_width = 100
spawn_pipes(pipe_width, random_height_size, pipe_location, 0)
spawn_pipes(pipe_width, bottom_size, pipe_location, bottom_height_position)
If you look closely, the problem appear when you excecute the func spawn_pipes(x_size, y_size, x_position, y_position)
twice. Or once in the func spawn_double_pipes(pipe_location)
. All of this, meanwhile func movement()
is activated.
So the question is, How to set the pipe movement in a normal pace? How to avoid this crazy and fast movement? Are there any concept that I’m not aware of? What do you think?