1
votes

I have Crane Animation which will pick the sand (through its jaw) and drop it to the truck. I tried to find the way to handle sand in Unity but unfortunately found nothing. So I made custom sand object (low poly) in max and bring them it Unity3d and apply box collider and rigidbody to them. But as I play the game, my FPS drops and player hardly moving. Profiler tell that physics is so heavy (and it should be as too many colliders with too many rigidbodies). I tried to optimize physics by collision matrix and layer but it didn't improve the performance.

Is this right approach to handle sand interaction with a crane?

1
Why did you tag this C#? Where is the relevant code? Also doing fully "realistic" sand simulations is usually overkill - using a particle simulation (to display sand flow) and then moving the sand from crane to truck is often sufficientUnholySheep
Hi, there is no code yet. The reason i add C# that maybe any coding solution available to handle this problem. If you have a better alternative then you can answer. Thats why i also asked alternate approach.Muhammad Faizan Khan
I already suggested an alternative - use a particle simulation to show the sand flow and move it over once some threshold is reached. If you need a more realistic solution you'll have to write quite a bit of code (including things like mesh deformation and dynamic generation of meshes) in order to have decent performanceUnholySheep
Seems tough even with particle system. Can you suggest any good tut or reference? Anyway thanks for your contribution.Muhammad Faizan Khan
Basically you should go for voxels on the sand that is on the terrain and GPU particles for the effectPino De Francesco

1 Answers

-1
votes

You could have the sand be a terrain and use the terrain.SetHeights() Method to lower a specific area of the terrain where you used the crane.

It would look like those classic terrain editing tools when you lower or heigher terrain.

Then wherever you "drop" off the sand you could heigher the area a bit.

I found this thread with some code examples to help you get going: https://forum.unity.com/threads/edit-terrain-in-real-time.98410/

private void raiseTerrain(Vector3 point)
{
    int terX =(int)((point.x / myTerrain.terrainData.size.x) * xResolution);
    int terZ =(int)((point.z / myTerrain.terrainData.size.z) * zResolution);
    float[,] height = myTerrain.terrainData.GetHeights(terX - 4,terZ - 4,9,9);  //new float[1,1];

    for(int tempY = 0; tempY < 9; tempY++)
        for(int tempX = 0; tempX < 9; tempX++)
        {
            float dist_to_target = Mathf.Abs((float)tempY - 4f) + Mathf.Abs ((float)tempX - 4f);
            float maxDist = 8f;
            float proportion = dist_to_target / maxDist;

            height[tempX,tempY] += 0.001f * (1f - proportion);
            heights[terX - 4 + tempX,terZ - 4 + tempY] += 0.01f * (1f - proportion);
        }

    myTerrain.terrainData.SetHeights(terX - 4, terZ - 4, height);
}