I’m transitioning between locations. It is designed in such a way that when the player’s character touches the trigger, the trigger saves the pre-recorded values to the global script variables. A total of three variables are used. Two of them are horizontal and vertical positions. The third only shows whether the player has been moved to another location and whether it is necessary to change his position. However, when I write in the script of the target location so that it would move the player to the desired coordinates after teleporting him, he does not move anything and the character does not appear at the entrance, but where I left him editing the scene. What do you need to do in general to be able to move any object to another coordinate point?
p.s. First, I indicated the text of the question in the version column
i would need to know the code of how you currently move the character.
Teleporting an character is done by setting its position/global_position value.
Moving an object requires time duration and also whether to move him via physics (direction * speed) or constantly (maybe tweening the position)
I cleaned up this code. But I just used “$Frisk.velocity.x(or y)=SceneChange.target_tp_x(or y)” at the entrance to the location. “Frisk” is the name of the object that is the player’s character. “SceneChange” is a global script. In it, the target positions are stored vertically and horizontally. But it gave an error, so it is obvious that nothing will work like this.
You should only set the velocity from within the character’s _physics_process() method because otherwise it will be reset on each frame.
For now I believe you want to teleport the Frisk player to a specific point. $Frisk.position = Vector2(SceneChange.target_tp_x, SceneChange.target_tp_y)
Right now I assume the player character is a CharacterBody2D
But it gave an error, so it is obvious that nothing will work like this.
Could you post the error so I am able to see what’s up? It can also be that SceneChange.target_tp_x is null which would mean that your position saving code is faulty.
E 0:00:05:0247 frisk_home.tscn::GDScript_j1eee:10 @ _on_body_entered(): Removing a CollisionObject node during a physics callback is not allowed and will cause undesired behavior. Remove with call_deferred() instead.
Can I ask you to post the code for the _on_body_entered() method? I believe the method is trying to alter the physic collision characteristic of a body while it’s still processing.
Yes! The player is transported to the desired location. But in the console it gives two errors. “E 0:00:04:0827 scene_change.gd:9 @ scene_transition(): This function can’t be used during the in/out signal.”
and
“E 0:00:04:0827 scene_change.gd:9 @ scene_transition(): Removing a CollisionObject node during a physics callback is not allowed and will cause undesired behavior. Remove with call_deferred() instead.”
But nevertheless, nothing bad happens to the game itself. So I guess I can just leave it at that.
This error is caused by the presence of this line: get_tree().change_scene_to_file("res://Scenes/a.tscn")
Do you really need it? I guess you are in this scene right now
Could I ask you to change the line get_tree().change_scene_to_file("res://Scenes/a.tscn")
into get_tree().change_scene_to_file.bind("res://Scenes/a.tscn").call_deferred()