Godot Version
4.5
Question
Hi
I’ve just updated from Godot 3.4 → 4.4, got everything working as before a fair amount of issues but I got it done. Last weekend I updated from 4.4 to 4.5 and didn’t really expect any issues. But I have one major issue with tilemaps.
I have a layer with ladders on it. when the player intersects the ladder and presses up I need to calculate the center of the tile, and then over a few frames I slide my player over to be centered on the ladder as they ascend or decend. This stops the player from colliding with platforms as they climb.
The code below worked in 4.4. The center of the player and the center of the ladder were always, within width/2 of the ladder and the slide worked.
In Godot 4.5 the character jumps off the ladder and quite a way to the left.
The calculate feels right and certainly worked previously, but it now feels like there’s an offset that’s been included in the engine or my original calculation was totally wrong.
Does anyone know if there was a change in the engine or is this calculation just plain wrong
Fred has intersected with a ladder, prepare to center him on it if
the player presses up to climb.
func _on_ladder_collisions_layer_body_shape_entered(body_rid: RID, body: Node2D, body_shape_index: int, local_shape_index: int) → void:
var centerOfTile: Vector2 = _get_tile_center_in_global_coords(body_rid, body, body_shape_index, local_shape_index)
# passing the coords of the center this will allow us to slide fred until he
# is centered on the ladder and not hitting platforms at the top
_ladder_status_changed(body_rid, centerOfTile, true)
From a collision with a tile map layer, map the collided cell into global coordinates
returns - A Vector2D thyat is the center of the intersected cell
func _get_tile_center_in_global_coords(body_rid: RID, tilemap: TileMapLayer, body_shape_index: int, local_shape_index: int) → Vector2:
# Get the tile’s cell coordinates from the shape index
var cell = tilemap.get_coords_for_body_rid(body_rid)
# Convert cell to local position
var local_pos = tilemap.map_to_local(cell)
# Convert local position to global position
return tilemap.to_global(local_pos)