Need Help with falling platforms

Godot 4.4

I am facing an issue with falling platforms. The Falling platform is placed on a position in the scene but when I play the game it move to (0,0) position(see the screenshots ).



I am using a character_body2d as the root of falling platform, a sprite2d, animation_player and a timer. I have used same method to create falling platform in godot 3. Thanks in advance.

Here is my code:
extends CharacterBody2D

@onready var animation_player = $AnimationPlayer
@onready var timer = $ResetTimer
@onready var reset_position = global_position # Store initial position

var is_triggered = false

@export var respawnable = false
@export var reset_time: float = 2.0

func _ready():
#reset_position = global_position
set_physics_process(false)

func _physics_process(delta: float) → void:
velocity.y = Global.GRAVITY * delta
position += velocity * delta

func collide_with(_collision: CharacterBody2D, _collider: CharacterBody2D):
if !is_triggered:
is_triggered = true
animation_player.play(“shake”)
velocity = Vector2.ZERO

func _on_animation_player_animation_finished(anim_name: StringName) → void:
if anim_name == “shake”:
set_physics_process(true)
timer.start(reset_time)

func _on_reset_timer_timeout():
if !respawnable:
self.queue_free()
print(“deleted”)
else:
set_physics_process(false)
await get_tree().physics_frame
var temp = collision_layer
collision_layer = 100
global_position = reset_position
await get_tree().physics_frame
collision_layer = temp
is_triggered = false

my guess is your AnimationPlayer set the position to 0,0 initially

1 Like

Thanks. I really missed that. I was animating the CharacterBody2D instead of sprite2D.