4.3_stable
Question
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
someone help
You can make code format nicely here via:
```gdscript
code
```
# 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
I’m assuming here that _on_void_body_entered()
is being called with a Node2D
which can’t be upcast to CharacterBody2D
, and hilarity is ensuing.
I changed the Node2D in the Checkpoint code, and it didn’t remove the error message. Any other ideas? (also sorry about the code formatting)
I think they meant on the Player script, here:
body_entered
signals emit a Node2D, which is not implicitly castable to CharacterBody2D so the observer fails.
1 Like
so that got rid of the error message but now a new problem has arisen; it’s respawning me in a completely different spot then intended
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;
i dont know why this happens, there is NOTHING there to anchor to?
oh and sorry for completely changing the topic ;-;
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.
2 Likes
didn’t seem to work… i changed checkpoint.gd at this part
i might have that wrong tho
What did you change the line of code to? How does your script look now? That quote is the correct place to replace position
with global_position
.
changed that to
PlayerGD.RespawnPoint = get_node(“Spawnpoint”).global.position
thats it
And what does “didn’t seem to work” mean? How does it fail? What did you expect to happen versus what really happened? Do you get an error?
it didn’t change anything, its supposed to respawn the player at the checkpoint, but it respawns them at the place mentioned before
no error message
In the editor what’s the value of the “Spawnpoint” node’s position?
oh my god it’s relative to the parent node
it says its at 0,0 meanwhile its at where the parent node is
is there a way to fix that?
i still havent been able to fix it
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.
I see you’ve made a new thread here: Player teleports to wrong spot after death
Make sure to mark the solution for this thread; this post specifically