Godot Version
4.3
Question
`Hi. I’m trying to translate a Godot 3 tutorial into Godot 4 as an educational experience. Educational in that I learned that I want to pull my hair out.
Currently I have an issue following this tutorial(https://youtu.be/VRVWfwZcq-s?si=0ag1Tnjwmf1qwRxP)
I am trying to make it so that the bubbles that I shoot from the player, become attached to the tilemap when they connect to the bubbles on the tilemap. Along with the code below I’ll attach my full project as it is in case it’s not clear what I’m trying to do. Any help would be greatly appreciated
The code featured in the tutorial is:
Bubble.gb
extends RigidBody 2D
signal bubble_stopped
var type = 0
func _on_Bubble_body_entered(body):
if body.collision_layer > 1:
lock bubble()
func lock_bubble():
emit_signal(“bubble_stopped”, position, self, type)
level.gb
func bubble_stopped(pos, bubble, type):
pos = $TileMap.world_to_map(pos0
$TileMap.set_cell(pos.x, pos.y, type)
bubble.queue.free()
bubblespawner.gb
new_Bubble.connect(“bubble_stopped”, get_parent(), “bubble_stopped”)
My Progress
level.gd
func bubble_stopped(pos: Vector2, bubble: RigidBody2D, type: int):
var tile_map = $TileMap
var map_pos = tile_map.local_to_map(pos) # Updated method
tile_map.set_cell(0, map_pos, type, Vector2i(0, 0)) # Updated for TileMap API
bubble.queue_free()
bubble.gd
signal bubble_Stopped
func _on_body_entered(body):
# Check if the body is a TileMap node
if body is TileMap:
lock_bubble()
func lock_bubble():
bubble_Stopped.emit(global_position, self, type)
bubblespawner.gd
new_Bubble.bubble_Stopped.connect(get_parent().bubble_stopped)’