Why my character teleports next to the teleport?

Godot Version

4.2.1

Question

Hey! So I created this teleporter in my 2D platformer and I would like the player stay on the block after teleporter, not spawn next to it, but I don’t know how.
Bug_gif

This code is from my player code:

Teleporter

func Teleport(area):
for portal in get_tree().get_nodes_in_group(“portal”):
if portal != area:
if(portal_id == area.id):
if(!portal.lockPortal):
area.LockedPortal()
global_position = portal.global_position

func _on_hitbox_area_entered(area):
if(area.is_in_group(“portal”)):
if(!area.lockPortal):
Teleport(area)

This is from my teleporter code:

extends Area2D

@export var id = 0

var lockPortal = false

func LockedPortal():
lockPortal = true
await get_tree().create_timer(0.5).timeout
lockPortal = false

Can you show your teleporter scene? Is the teleporter is offset from it’s scene root? Is the player offset from it’s scene root?

1 Like

This is the level’s Scene root

This is the teleporter’s(Portal)
portal

So in that portal scene is the sprite, collision shape, and static body2d at position (0,0)?

Yep, all of them.

and for the player? Do all of their children have position (0,0)?

Nope, the Animated sprite and all of the collision shapes are not.
Screenshot 2024-09-24 221252
Screenshot 2024-09-24 221303
Is that perhaps the reason for this?

1 Like

Seems like that could do it. Maybe you still want your root to be at the player’s feet though, so they teleport on top of the teleporter, rather than inside it. Like this:

Thank you so much! This is fixed now!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.