Stick on moving Platform

Godot Version

4.6.2

Question

Currently if you jump with the player controlled CharacterBody2D on the platform, it just slides away under you. How can I “stick” the player to it so you dont fly off

extends AnimatableBody2D
@export var pos1 : Vector2
@export var pos2 : Vector2
@export var duration = 2.0
var waspos1 = true
var previous_position : Vector2  # NEU

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	position = pos1
	move(pos2)


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	pass

func move(target: Vector2):
	if target == pos1:
		waspos1 = true
	else:
		waspos1 = false
		
	var tween = create_tween()
	tween.set_process_mode(Tween.TWEEN_PROCESS_PHYSICS)
	tween.tween_property(self, "position", target, duration)
	
	if waspos1:
		tween.tween_callback(move.bind(pos2))
	else:
		tween.tween_callback(move.bind(pos1))

image

Why do you have an entire TileMapLayer attached to it? Try a Sprite2D with an AtlasTexture instead and see if that solves your problem.

1 Like

Oh thank you so much it works now. I attached an entire tilemap because the platform consists of multiple tiles. Didnt figured out how AtlasTexture works yet, so i took a placeholder sprite.

1 Like

If you need to, just make multiple Sprite2D nodes and put them next to one another. Then load the tiles into each part. Save the scene and you’re done. Like this:

If that solution worked for you, please mark it as the solution for people coming after you.

1 Like