Hello folks,
I am trying to learn the Gadot 4+ also new dev here.
i was making a small space game where player just has to skip or shoot the meteors.
so i created a timer auto-started it and on_timer_timeout i add new meteor scene to the parent node of the scene
but the meteors do not move. Meteor is a Area2D node hence i have been updating position in _process func Please help. Here is the code
extends Area2D
@onready var player = $"../../Player"
@export var meteor_speed :=400
func _ready():
var width = get_viewport().get_visible_rect().size[0];
var rng = RandomNumberGenerator.new();
var random_x = rng.randi_range(0,width);
var random_y = rng.randi_range(-150,-50);
position = Vector2(random_x,random_y)
func _process(delta):
position += Vector2(0,1) * meteor_speed * delta
func _on_body_entered(body):
if body.name == 'Player':
print(body)
and here is code where i add new meteor
extends Node2D
@onready var meteors = $Meteors
var meteorScene:PackedScene = load('res://scenes/meteor.tscn')
func _ready():
pass # Replace with function body.
func _process(_delta):
pass
func _on_timer_timeout():
var new_meteor = meteorScene.instantiate();
meteors.add_child(new_meteor)
Please help me on what i am doing wrong, thank you