Hello! I’ve got a bit of a math problem:
I have an object that is 128x128 in size, and on top of that object I have an Area2D with a CollisionShape2D, that is also 128x128 in size.
I have an export variable called “size_mult”, which should multiply both of the sizes equally.
When “size_mult” is set to 1, they are the same size:
If the “size_mult” is set to 0.8, the CollisionShape2D is smaller than the object:
elif, the “size_mult” is set to 1.2, the CollisionShape2D is bigger than the object:
The resize code is quite simple and I don’t know what should be changed in order to make it work perfectly:
When you multiply the size_mult variable by Vector2(0.5, 0.5), the amount you scale it by changes as well (if size_mult were, say, 2, (1 × 2 = 2), the scale for the base object, but (0.5 × 2 = 1), the scale for the area.).
Instead,
Multiply the scale first, then scale down to the smaller size using subtraction (size_mult - Vector2(0.5, 0.5)) or
My favorite choice, Set the obj_area.size to be the same size as obj_tile.size as a base so the scales are the same.
(For possible future readers that have the same problem, my size_mult variable is a float, which is why I multiply it with a Vector2(1, 1). If you have it as a Vector2, (which is smart, because then you can control x- and y-scaling separately) you don’t need to multiply it with a Vector2(1, 1))