i stuck in a Problem with my RTS…
My Scenes are build of single tiles. each has the same XZ size (squared). When i want to create the whole map, i need to create 320*320 Tiles… wich kills the loading time, fps and memory…
now i thought: why not create 4030 Tiles, and shift them when scrolling with the camera. So there´re always 4030 tiles, that change their Look according to a ID Array.
My problems:
1st: The FPS drop under 10, when scrolling…
2nd: The camera overtake the mapshifting, so you quickly see the edge of the 40*30 field when scrolling…
This is exactly what I did with SpriteTile. To fix problem 1, well, all I can say is write good code. It turned out to be harder than I thought. But I eventually managed it, and you can see in this demo that there are a million tiles in the level with no speed problems. (I’ve also tested on mobile and it gets 60fps easily on my iPod touch.) For problem 2, basically I have an extra tile around the edges of the screen, so tiles get shifted in before you can see them.
What about instead of making a 4030 array, you make a 4131 array, so it’s a bit bigger than the screen, and when camera scrolls, you add one row in the new direction, and delete the row in the opposite direction?
Ok - so I’m guessing the main problem is the number of solid dirt blocks? If you removed those, would the game run fine? I was working on a similar game a while ago - from memory I rendered the dirt blocks using a single plane, and added a depth buffer to cut out the holes. so the only actual tiles I had were the corridors/rooms…
Let me know if you think that might help, I’ve got the code here somewhere
The visible area of the camera is 3624 blocks, so i already have a border with the 4030 array.
i tried the depth buffer, but it wasn´t the look i wanted… so i need to use single tiles for each wall/room/way situation.
All tiles are sharing one and the same material, just with different UV coordinates…
It´s not that the game is running slowely… it´s that the shift mapping isn´t working… and the re-instantiating of tiles according to new tile IDs kills the FPS (…i think).
Currently, my map is made out of Roof tiles.
This is one roof tile:
All 40*30 tiles are using the same material (diffuse bump). But even without re-instantiating (cause all are roof tiles), the fps drops under 50 ._.
How about:
1 - Have 2 seperate maps - one for the ceiling, one for the rooms/corridors etc
2 - Parent the ceiling map to the camera container (so it always moves with the camera)
3 - As the camera scrolls, calculate and set the MapHolder position based on the offset of the camera position:
var buffer = 5f; // This should be equal to the number of extra tile rows/columns outside of the camera view, ie 5 per side
var mapX = DKTiles.TheCameraParent.transform.position.x % buffer;
var mapZ = DKTiles.TheCameraParent.transform.position.z % buffer;
// May have to switch these to subtract:
// Note: MapBasePosition is a public Vector3 I added to my local script which aligns the map with the camera
MapHolder.transform.localPosition = new Vector3(MapBasePosition.x -mapX,0f,MapBasePosition.z -mapZ);
This will make the map stay with the camera, appear to endlessly scroll - without having to move any of the tiles - and performance should be a lot better since we’re only changing the transform of one game object instead of looping through a set of 30-40.
Secondly, you’ll need to hide/show ceiling tiles when you want to display a room/corridor. You could try calculating these yourself by working out the positions of these objects and hiding/showing the ceiling tiles as required, but I’d look at using triggers somehow instead - when a room tile collides with a ceiling tile then hide the ceiling. Re-show it on Trigger Exit.
Edit: Just tried out an example with triggers, definitely not a good idea - FPS drops significantly. I’d suggest adding all ceiling tiles to an array, and everytime the global position of the ceiling tilemap changes - do the room check manually.
but… the ceiling has a stone optic… see the screens…
when the ceiling always moves with the camera… it looks weird when there only holes are popping out of a not moving plane ._.
I’m not seeing the FPS drop to below 10 FPS in that portion of the profile. You need to record the part that actually has the slowdown in, otherwise we won’t see anything useful.
What if you have all of your objects in the scene but disable the ones that are out of view so they consume little cpu (except culling), and then activate/deactivate as you scroll?
Also are you using a pool of pre-allocated objects that you can pull from instant of like instantiating or whatever?