Player teleports to wrong spot after death

4.3_stable

Question

Reposted because i’m not getting any answers.
I’m using Godot 4.3 and I have a checkpoint system I’m working on. Whenever I die, it sends me to this random spot on the map (graciously circled in red.) The red collision shape is the thing that kills you, and the thing i have selected is the checkpoint.
There’s two scripts in play here. I’ll send them in other messages as i reach the limit already

I’ve been trying to solve this for an ENTIRE DAY now.
here’s the scripts I’ve been using.

Checkpoint.gd

extends Area2D
@onready var PlayerGD = $"../Player"


func _on_checkpoint_body_entered(body: Node2D) -> void:
    if body.is_in_group("Player"):
        print("wrong body actually :'(")
        PlayerGD.RespawnPoint = get_node("Spawnpoint").global_position

Player.gd

extends CharacterBody2D


@export var SPEED = 400.0
@export var JUMP_VELOCITY = -450.0
var fastfallcheck = false
var HasResize = true
var ResizeOn = false
var RespawnPoint = position

func _physics_process(delta: float) -> void:
    # Add the gravity.
    if not is_on_floor():
        velocity += get_gravity() * delta

    # Handle jump.
    if Input.is_action_just_pressed("Jump") and is_on_floor():
        velocity.y = JUMP_VELOCITY
    if Input.is_action_just_released("Jump"):
        if fastfallcheck == false:
            velocity.y += 250
            fastfallcheck = true
    if is_on_floor():
        fastfallcheck = false


    # Get the input direction and handle the movement/deceleration.
    # As good practice, you should replace UI actions with custom gameplay actions.
    var direction := Input.get_axis("Left", "Right")
    if direction:
        velocity.x = direction * SPEED
    else:
        velocity.x = move_toward(velocity.x, 0, SPEED)

    if Input.is_action_just_pressed("Up"):
        if HasResize == true:
            if ResizeOn == false:
                scale = Vector2(2,2)
                JUMP_VELOCITY = -750
                ResizeOn = true
    if Input.is_action_just_pressed("Down"):
        if HasResize == true:
            if ResizeOn == true:
                scale = Vector2(1,1)
                JUMP_VELOCITY = -500
                ResizeOn = false
    move_and_slide()





func _on_void_body_entered(_body: Node2D) -> void:
    position = RespawnPoint

FIXED; i had the checkpoint function as “on_checkpoint_body_entered”, while it was SUPPOSED to be just “on body entered”. at least i THINK thats the problem

1 Like