0 votes

I have multiple rails. All rails start with process to false, and i have an AI very simple that each 2 seconds choose between 3 rails and set a train. When the train reach the end of the rail swap the train to another rail (This rail is dynamic and can be there like not) and here is where the "magic" happen. When the train has no reach the end yet the delta is 0.016, but when swap the rail to another the delta is 0.113 and this doesn't happen to each process, just happen to the dynamic rail process. Have any idea why this happen? Sorry for the english.

**Edit 1: **

I found the solution but the problem wasn't directly the delta. When the train jump from one rail to another i don't dereference the train from the old rail so the process that calculate the position of the train was executed two times. Maybe this make the high delta value problems.

in Engine by (18 points)
edited by

1 Answer

+1 vote

All I can say is that your game is probably laggy. What you are doing at switching time is maybe a heavy operation (like loading, creation of lots of nodes or a big fragment of code, directly or indirectly) that makes the game hang for longer than a frame.
If you don't think that's a heavy operation, please explain what you are actually doing^^

Delta is not supposed to be always the same, that's the reason why it exists and is passed to all process functions. You have to deal with it and update your code so it doesn't break if framerate fluctuates.

by (29,090 points)

When the game start, it load all the resource so i don't think the resource is the problem. But when the train is in the dynamic rail i do this:

Globals.get(global.actives_rails).append(self)
print ("active rails: ", Globals.get(global.actives_rails).size())
set_process(true)
set_train (train)

and in process i do this:

func _process(delta):
if not has_train ():
    return
    pass
origin_pos = train.get_pos ()
destiny_pos = destiny.get_pos ()

var train_pos = train.get_pos ()
var new_y = train_pos.y - (delta * train.get_speed ())
train.set_pos(Vector2(train.get_pos().x, new_y))

I was thinking to use my own delta to keep the things stable, because the game is for one player.

I don't see heavy stuff here, but other functions are called, I can't tell what's going on. if you are sure delta is dropping exactly at the moment when you switch rails, follow all things you do at this moment and search what can cause the slowdown (printing, for example :p).

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.