• Register
Post news RSS Devblog 12 - Marrying the building system with the terrain - Part 2

We pick up where we left off: The construction system constantly detects collisions with the ground.

Posted by on

We pick up where we left off: The construction system constantly detects collisions with the ground.

(Red is that it does not allow building, white is that it does).

As I indicated, there can be 2 types of collisions, vertical that are "expected" (since the brick collides with the studs of another brick) and horizontal, which are real collisions since they occur when the models are crossed.
In order to fix something like this we should check all the intersection points between the 2 objects and discard the vertical ones. But we are trying to fix a problem derived from another problem.
The real problem is that to generate the collider of each chunk, I am using the shown mesh. That means Unity takes brick studs into account, making it a hell of a costly operation as well as an unwanted one.

As painful to generate as it sounds.
If you remember, the GridStuds of our bricks are square colliders:

(the green)
At no time we do take into account the shape of the studs, we don't care. And with the terrain we should do the same.
How are we going to do it? Creating a new model that is a simple cube. We grab the brick and remove the studs and the bottom. So it has the same measurements, but it is a cube.

And we have to edit the generation of chunks, so that 2 meshes are created, 1 that takes into account the studs and another that does not.

Almost everything is copy & paste of what i have already done, we just have to remove the uvs and colors part since we do not care.
I tried generating and the terrain and... Damn, what a difference with the loading speed. It is not as painful as before.

With this play we have achieved several things:
- Reduce loading times by simplifying the mesh used to generate colliders
- Not have vertical collisions.
- Improve "walking". When the studs had collisions, it seemed that you were walking through mountains, with mini-mountains all the time. Now despite being shaped, the terrain is flat when walking.
Now that we don't have vertical collisions, the collision detection system should work without requiring any editing.

If you notice, in the last part of the video I can't place bricks between the ground and other bricks.

This is because of something that I have avoided talking at all times: The bricks on the map are placed at a different height than those placed by the player.
There is always a small space between the player's bricks, which in my opinion gives it a more "Lego" touch:

If I put them like on the map, I think some of the essence / grace would be lost:

Much to my regret, I'm afraid I have no alternative, because I could put that space when all the faces of the model are rendered. On the terrain we don't do that, so if I put the space it would literally look transparent / the map inside.

I'm celebrating it too early because of something I have not shown it in the video: the bricks that you connect from the ass of another brick still have the wrong height. I will see if I can fix it easily too.

Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.