I was looking at my minimap example again (GDevelop Dynamic Map by Silver-Streak), and going through some more testing, to find out a rather large flaw.
Super high level:
I have 2 different sprites that have different starting points.
I want to keep the movement between the sprites relatively the same . So if Sprite 1 moves forward X amount, I want sprite 2 to move forward X amount, and backwards the same negative amount.
I need this to be dynamic enough that I can move the starting points around as the game progresses/characters load saves.
How should this be done?
My minimap works by having an external layout of the map with each room scaled to 1/40th the size. (So, 1280x720 rooms become 32x18). There is a “CurrentPosition” object to represent the player (normally hidden) also scaled to 1/40th the size (~1x2).
As you move the player in the world, the “CurrentPosition” object moves through the minimap boxes, exploring them which makes them visible.
The minimap’s boxes do not have X/Y that directly correlates to the game rooms simply because the minimap will eventually have the whole game map, where as each scene will only have a portion. So if the player is starting at 0,0, the minimap starting room is 256,342. (This is the StartRoom.X and StartRoom.Y in the below screenshot)
Everything works as intended, but only if the starting point of the player is basically 0,0. But not elsewhere.
I’ve narrowed down the issue to my relative movement for CurrentPosition.
What I’ve realized is that if the player is starting at/near 0,0, that means as they move, they’re only adding however much X/Y to the relative position, which kept it as close to 1:1 movement as possible.
So if I start from the 0,0 room, and move over a few rooms and up a few rooms, I end up in the game world at 2560,-720. In the minimap, this has me end up at 384x306, as I’ve moved from 0 to where I should.
However, say the player starts at 2560,-720 in the world. This means, for the player, the relative X is 64, and the Y is -18.
If on the minimap, this room’s position is 384x306, my above formula instead makes the “CurrentPosition” be 448, 288.
How do I fix this?
Is there a better way to do this type of relative position with an offset?
It’s currently 4am because I’ve been trying to rack my head around this, and it’s probably too big of a question for the discord, so any help is greatly appreciated.
The full project files can be downloaded at the above link, but please let me know if you’d like any other info/examples/etc.