Godot Version
4.3 stable
Question
Hello! I am a complete noob at gamedev and I’m currently making my first game project that is basically a tetris clone with a few extras.
When moving / rotating the falling pieces, I need the collision shapes and raycasts to respond instantly, to prevent the piece from going off-bounds or stuck in other pieces. However, if the Sprite2D is attached to each block, it also blinks instantly to the new location. I’m looking for a way to make the movement smooth without affecting gameplay mechanics.
My first idea was to make the sprite not a child of the object with the collision shapes, and on each move I’d get the current location of the Sprite and use a tween to move it to the location of the collision object. This looked really nice visually, but it was an incredibly poor decision, because it made coding the rest of the systems a nightmare. At some point after hours of hitting my head against a brick wall I rewrote everything, so the Sprite2D now IS a child of the collision object.
Now I’ve tried getting the position of the object before moving it, waiting one frame, then animating from the saved positions to the new positions, but it causes all kinda of jittering and blinking around.
If you want to see my noob spaghetti code, here you go, but I don’t think I have the right idea at all. Is there an easier way to do this, like for example the camera object that has smooth following?
func _animate() -> void:
var old_positions : Array
for item in $".".get_children():
old_positions.append(item.get_child(-1).global_position)
await get_tree().process_frame
var tween = create_tween()
var index : int = 0
for item in $".".get_children():
var sprite = item.get_child(-1)
tween.tween_property(sprite, 'global_position', Vector2 (item.global_position),0.15).from(Vector2(old_positions[index]))
index += 1