#teleporting to wrong spot?

7 messages · Page 1 of 1 (latest)

atomic fractal
#

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 HOUR now. I will provide any extra neesary information

#

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

#

and yes i copied this from the official godot dc

#

might take a while to respond btw

mild turtleBOT
#
Embedding code in discord messages
Inline Code

When you surround some words with single backticks like `this`, it will be formatted as code.

Code Blocks

You can also include code blocks by surrounding the code with three backticks. If you add "swift" then you will also get basic syntax highlighting:
```swift
print("hello world")
```
Discord will then show it as a code block like this:

print("hello world")
Upload

If your code snippet is rather long, you can upload it to a text paste site. One option that supports syntax highlighting for GDScript is https://bpa.st/

solemn abyss
#

that "random spot" you're showing is the global origin.
My guess is that your Area2D's origin is at the same point, but you have your collisionshape offset

#

after you set PlayerGD.RespawnPoint try printing that same value. If it prints (0,0) that will answer the question