I have a teleport system where an object enters a teleport, is scaled down to 0, then moved to another teleport, and scaled back up again. This works very nicely, except that upon exiting the teleport, my object is off-center by a pixel or so and therefore is able to collide with objects above or to the side of the teleport. This shouldn’t happen. I’ve tried using a ‘Snap to virtual grid’ action, but the snapping happens too late (after the collisions have already occurred).
EDIT: To clarify, all my objects are 64x64, as is my grid. So the Squibble (pink ball) will collide with the coins if it’s only 1 pixel off-center. And no, I don’t want to change the collision mask of my coins to work around this issue if at all possible…
Yeah, but that only avoids the problem; it doesn’t solve it… It’s also possible that another teleport is next to or above the teleport the Squibble exits from. And I can’t change the collision mask of the Teleport object…
You might just need to loosen up the masks. There’s going to be a little variability. There should be a little room for error.
As the ancient proverb goes; you can have high precision, a high refresh rate or high resolution graphics but you can’t have all 3. It’s all a balancing act.
So it’s almost as if the Squibble is placed and then enlarged, rather than the other way round. Maybe raise it as a bug?
In the meantime, just a thought - what if you change the origin to be the same as the centre point? After all, you are expanding from the centre of the Squibble, then if that’s where you place it, it should [theoretically] avoid the problem. I realise this will mess up the current positions of objects, but it may circumvent the issue.
Unless anyone comes up with a better solution, I’ve worked around the problem simply by adding a condition to the coin collection and teleport events that requires the Squibble to NOT be in the “teleporting” state (i.e. don’t collect coins or enter other teleports until the current teleportation is complete). That seems to work for now, and doesn’t require changing origins or collision masks (which might require additional changes to my game).
You can save the center position of the tweening object before the tween, and while tweening, you set the position to it’s center position continuously.
When I don’t include this event, any random ‘coin’ around it might get collided with:
But there is no more issue if you recenter the sprite constantly during the tween as in the example screenshot above:
If instead you use conditions to define when the collision is active or not as you did, it’ll be easier to make mistakes later on when you grow the game.
Genius! Thank you for that wonderful solution. Simple and works nicely!
I’ll keep my GitHub bug report open as, ideally, this wouldn’t be necessary to do (@LeakySafe’s solution is how I’d expect this to work by default). But this topic is solved.