I have a character that it moves upward and it has a camera that follows it. Building the project on my computer the game hasn’t problems. But, bundling the game on mobile the character starts progressively wiggling as it moves on.
I have tried both orthographic camera and rendercam and it has the same effect.
This is what happens on my iPhone 6 with iOS 12.2 (I have even tried on an Android device and it does the same thing):
Defold 1.2.152
Basic test project: Camera bug.zip (3.6 MB)
From what I’ve heard is that position floating points loose precision on big numbers and you are moving 1000 pixels in second (by floated number per frame).
Just an idea - try this in player script
function update(self, dt)
local pos = go.get_position("hero")
pos.x = pos.x + 1000 * dt
local p = pos
p.x = math.floor(p.x)
go.set_position(p, "hero")
end
Thanks for the suggestion.
I tried that but unfortunately the result was the same.
I should also have mentioned that this is a simplification of a problem on my actual game, where there is a character that can jump on different platforms that evolves upwards, and when the character reaches high y coordinates, when it jumps, it wiggles like the gif posted above. So I think that the problem is related on the coordinates when they become very big.
The position of your game object will translate to a world position when rendered. The camera will render at a specific position in the world. We will not translate everything to 0 before it is rendered.
But if you move all the objects and keep the player still, this issue would affect every object. Seems like the only way is to change the shader precision.
So basically I would need to put Player, tiles, background, etc under parent GO and whatever amount player moves I set the reverse value to parent GO?
That’s a weird solution but not a “deal-breaker” solution. Since my only real extended experience is with Gamemaker I know only the way it handled the situation and it is totally different and has no such problem, whatever the coordinates camera and objects are. Unless it offsets world in the backend automatically.
It all depends on the size of your world. For an endless runner it’s the de facto way of creating such games. For a platformer or top down game with moderately sized levels you don’t have to do it. For larger worlds it might not be needed if you increase the shader precision. What kind of game are you making? What’s the size of your game world?
Oh, for endless runner that’s understandable.
I’m primarily interested in platformer games and that made me a bit worried about world size, but if that trick of offsetting parent doesn’t give performance hit, I have no problem with that.
What is “super large levels”?
I’m a pixel art lover so, let’s say NES Contra or Megaman sized levels, but what if I’ll do team-up it probably will be bigger scale.
I took a look at Megaman 1 levels and the size is in the range of around 5-6000 pixels. Not sure what kind of precision that is required to render in this range without problems. @Mathias_Westerdahl and @jhonny.goransson do you have some input?
Imho, this is subjective.
In the range [4196, 8192) you have the precision 0.00048828125 which might not seem “large” enough to look weird, but remember that floating point “errors” progagate when you multiply with other floating point values (which the engine does a lot), so you’ll most likely see the errors grow.
E.g. in Just Cause, where the gameworld is 32km2, the coordinates are in the range [-16384,16384] and the single floating point precision is 0.000976562.
Each 512x512 meter patch, and all the objects in that patch, are translated back to origin, and updated in that space in order to keep precision high. If that wasn’t done, the animations would look very jerky, and the models/meshes wouldbn’t align properly etc.