Godot Version
4.7.2
Question
I’m new to Godot and programming so apologies if this is easy, I just can’t seem to find the solution.
So I have a CharacterBody2D node as my player with three children; AnimatedSprite2D, RayCast2D, and CollisionShape2D. I want to teleport all three and a camera when I interact with a door. The script attached is connected to the Area2D node of the door (FYI player script doesn’t have anything related to position. Just animations, velocity, and input checks)
extends Area2D
var inside = false
@onready var camera: Camera2D = $"../room_change"
@onready var player: CharacterBody2D = $"../Player"
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("interact"):
if inside == true:
camera.global_position = Vector2(901.0, 300.0)
player.global_position = Vector2(766.0,493.0)
func _on_body_entered(_body: Node2D) -> void:
inside = true
$arrow.visible = true
func _on_body_exited(_body: Node2D) -> void:
inside = false
$arrow.visible = false
The Camera2D and CharacterBody2D teleport exactly where I want them to however all of the CharacterBody2D node’s children get moved roughly around y500 from the position of the Character node.
I tested teleporting in a few bit other places and teleporting it anywhere within a few pixels of its starting position didn’t cause the children to move. Both position and global_position cause this.
Help would be appreciated.