• 2D
  • Can I use the scale property on a collision mask without unexpected collision behaviour?

The godot docs state:

Be careful to never scale your collision shapes in the editor. The "Scale" property in the Inspector should remain (1, 1). When changing the size of the collision shape, you should always use the size handles, not the Node2D scale handles. Scaling a shape can result in unexpected collision behavior.

I have a sprite that changes size during the game. As it changes, my code scales the collision shape to match.

I have a list of scales:

const COLLISION_SCALES = [
	Vector2(3.2, 3.2),
	Vector2(6.4, 6.4),
	Vector2(25.6, 25.6)
]

Then I can re-size the collision shape like this:

$Collision.scale = COLLISION_SCALES[index]

But I'm wary of the warning the documentation gives. Does the warning apply to the scale property as it does to the handles in the gui? Also, what might that unexpected collision be?

I don't know, Godot dev should show up soon. I think it should not apply there, but on the safe side, RectangleShape2D.extents CircleShape2D.radius LineShape2D.d or such should be use instant.

From my experience, I believe it is okay to scale a CollisionShape2D node, just not the physics node itself (KinematicBody2D, RigidBody2D, StaticBody2D). I have done so a few times and I do not remember having any issues scaling the CollisionShape2D nodes. Though if you can, modifying the size through the collision shape properties like @sent44 said, is probably the safest bet for not having issues.

@RegularGuineaFowl said: Also, what might that unexpected collision be?

The physics engine will not collide the objects correctly or accurately. Generally objects will slide up/down or move in a jitter-like motion rather than in expected ways. Additionally, the normal vectors returned by raycasts will be skewed.