Godot Version
4.3
Question
Hi everyone. I’m trying to stop movement of all objects (built from the same kind of node Pipelines.tscn
) when a character collide with just one object.
To explain a little the project, it is a Flappy bird clone. The player
doesn’t move, it just jumps, like it is shown down bellow
extends CharacterBody2D
var speed = 300
var gravity_constant = 100
var JUMP = -3000
func _physics_process(delta):
jump()
func jump():
if Input.is_action_just_pressed("ui_up"):
velocity.y = JUMP
else:
gravity()
move_and_slide()
func gravity():
velocity.y = gravity_constant
move_and_slide()
Instead of that, only the pipes moves. Those are build from an instantiate()
method, taking the values of Pipelines
scene into the Main
scene, like it is shown bellow.
Main.gd
extends Node2D
var pipe_node = preload("res://Scene/pipelines.tscn")
var screen_max_height = DisplayServer.window_get_size()
func spawn_pipes(x_size, y_size, x_position, y_position):
var pipe = pipe_node.instantiate()
pipe.create_pipe(x_size, y_size)
pipe.position = Vector2(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 = 200
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)```
To solve this issue, I tried the following solution inside Pipelines.gd
, However it just stop just one object, instead of stop all object’s movement.
func stop():
speed = 0
func movement(delta):
var collision_info = move_and_collide(delta * velocity)
velocity.x = speed
if collision_info:
stop()
Is there a way to affect all objects movement?