0 votes

hello, I need some help.

I using randi to create ramdomly three scenes.
but each time the scene is created, the velocity increases.

extends Node2D

var speed = 400

func physicsprocess(delta):

var pos_x1 = position.x
pos_x1 -= speed1 * delta
position.x = pos_x1

func createmap():
randomize()
var alpha = load("res://scenes/map" + str(randi()%3 + 1) + ".tscn")
var alphainstance = alpha.instance()
alphainstance.position = Vector2(5400,0)
add
child(alphainstance)
$Timer.stop()

func onlimitebodyentered(body):

if "ninja" in body.name:
    $Timer.start()

func onTimertimeout():
create
map()

in Engine by (35 points)

1 Answer

0 votes

I think I know where your mistake is but I'm not completely sure as your question is missing a lot of information and the provided code is formated horribly (and thus extremely hard to read). Please improve this for future questions.

Now to my possible explaination. Am I right guessing that this script is running in a map? Because if this is the case you would add the new map as a child of the exiting one and therefor the new map moves every time the parent map moves. After the parent has moved itself and the child the child moves itself as well. => Double movement every frame

To fix this try replacing "addchild (alphainstance)" with "getparent ().add_child (alphainstance)". If this doesn't help then we need more information about your code and file structure.

by (330 points)
edited by

ok, I have (for while) 3 scenes (I did with tilemaps but this doesn't matter).
I got to create them randomly .

the problem is:
when a new scene is created, it comes faster then previous one.

I don't know why if I declare all the scenes with the same value:

"var speed = 400"
is there any way to reset this variable somewhere?
I believe it is adding up or multiplying each time I create a new scene.

As I said. This is probably due to you adding every map as a child of the previous map. Change you add_child line to

get_parent().add_child(alphainstance)

If this doesn't help then we'll see further.

Hello Magnus, perfect!! Thank you. Now the scenes are created at same speed.

but sometimes bug and does't appears anything

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.