Godot Version
Godot v4.4.1
Background
I am building a Sushishot clone as a learning exercise (still pretty new to Godot) and also because my partner loves that game and would like to play a personalised version.
The core mechanic is merging of items into bigger items when they collide. Here is the approach i have taken.
- The playable area is boxed in by 4 x StaticBody2Ds (wall) and each item is a RigidBody2D
- When a collision is detected, a new Item is instanced at the point of collision between 2 items
- The new item is scaled from 0 to the desired size to avoid overlapping with other items and the walls.
Problem
When the collision point is too close to the walls (StaticBody2D) or another item, the new item scales into them and they end up overlapping. This causes all sorts of weird jittering or items getting “stuck” together or to walls.
Here is what i’ve tried with no luck on solving this issue:
- Scaling the RigidBody2D instead of the CollisionShape2D - did not help at all!
- Setting up an Area2D to detect overlap and applying a small force to the overlapping item back out - helped in some cases to help slide the item back out but doesn’t work if overlap is too much
- Adjusting the rotation of the new item to minimize the changes of overlap - helps a bit but doesn’t solve my core issue.
Question
What is the best practice when it comes to scaling RigidBody2Ds? I’ve found a couple older threads suggesting not to do this but doesn’t offer any viable alternatives.
Image and code snippet for scaling for reference:
func _ready() -> void:
# attach item to a game intance
_set_game_instance()
# set all children to scale from 0 to desired size
var children: Array = get_children()
for child in children:
# if it can be scaled (i.e not a timer node)
if child is Node2D:
child.scale = Vector2.ZERO
var tween: Tween = create_tween()
if child is Sprite2D:
tween.tween_property(child, "scale", target_scale, sprite_scale_duration)
else:
tween.tween_property(child, "scale", target_scale, collision_scale_duration)