0 votes

I'm trying to figure out how to make sure new instances(asteroids) spawn in front of my "player" when he is moving and the ones that are out of the view get deleted. because for now, each asteroid is spawning to slow behind the player. also how would you make them spin slowly when spawning, in different directions to look more like "realistic asteroids", if the asteroids come from the bottom up it doesn't bother me thats actually good to?
if this looks bad I barely know anything about codeing.

`extends Node2D
var preflyingobject= preload("res://objects/flyingobject.tscn")
var good

Called when the node enters the scene tree for the first time.

func _ready():

func _process(delta):

func onArea2Dbodyentered(body):

if "flying" or "player" in body.name:

func onTimertimeout():
if good
var new

in Engine by (12 points)

1 Answer

0 votes

This is a partial answer.

In order to delete things that are out of view, you can just add a VisibilityNotifier2D node to your asteroid scene. Then you can listen for screen_exited signal, and then go ahead and remove the node.

    > VisibilityNotifier2D

# Asteroid.gd

# you can put whatever you want here for the range
const ROTATION_SPEED = [5, 90] # in degrees/second
const rotation_amount = 0

func _ready():
    $VisibilityNotifier2D.connect("screen_exited", self, "_on_screen_exited")

func _process(delta):
    rotation_degrees += delta * rotation_amount

func _on_screen_exited():

func set_random_rotation():
    var direction = 1 if randf() > 0.5 else -1
    rotation_amount = direction * rand_range(ROTATION_SPEED[0], ROTATION_SPEED[1])

As far as where to instance nodes, can you provide a little more detail about the way things are set up?

by (1,650 points)
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 Frequently asked questions and 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 [email protected] with your username.