what does this mean? i have 2 scripts - “player.gd” and “Checkpoint.gd”
if theres someone out there that can help PLEASE HOW THE HELL DO I MAKE CHECKPOINTS WORK
Checkpoint.gd-
extends Area2D @onready var PlayerGD = $“../Player”
func _on_body_entered(body: Node2D) → void:
if body.is_in_group(“Player”):
print(“wrong body actually :'(”)
PlayerGD.RespawnPoint = get_node(“Spawnpoint”).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 @export 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: CharacterBody2D) → void:
position = RespawnPoint
# Checkpoint.gd-
extends Area2D
@onready var PlayerGD = $“../Player”
func _on_body_entered(body: Node2D) → void:
if body.is_in_group(“Player”):
print(“wrong body actually :'(”)
PlayerGD.RespawnPoint = get_node(“Spawnpoint”).position
# ----------------8<----------------
# Player.gd
extends CharacterBody2D
@export var SPEED = 400.0
@export var JUMP_VELOCITY = -450.0
var fastfallcheck = false
var HasResize = true
var ResizeOn = false
@export 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: CharacterBody2D) → void:
position = RespawnPoint
so THIS is the map of my game ; the part i have selected is the checkpoint and the red areas are the void that kills you. its supposed to respawn you near the checkpoint, but instead it respawns you HERE;
You’re using position for the checkpoint, but I suspect you might want to use global_position; the former is relative to the node’s parents (and grandparents, and…) while the latter is the computed final position.
It being zero makes sense if your code is using global_position it will take into account the parent’s position. That’s why it was sending you to zero when using position. Can you paste your full script again? something should’ve changed.