I am making a game where I need 10 boxes x 10 boxes stacked on top of each other like a square all together.
I have made this game already in Buildbox but I am converting it. In BB it is just to stack and set the boxes to dynamic.
If I try this in Unity and set all to rigidbody they all fall down. In fact I cannot even stack 6 boxes on top of each other with out them falling as soon as I hit play.
I have tried to set enable adaptive force which was a tip found but that will not help much. Cannot use extreme drag either.
Any good solution to this crap dynamic? Would not happen in the real world:)
Hi
Thanks for replying and I think I understand the different steps, but the boxes are behaving very strange. I have set the rigidbody to interpolate and continuous dynamic. I have a physics material set to 0 bouncing (also tried to change friction on both parameters).
The solver is on 6 and 1 but I changed both upwards in steps to 255 (seems to be max) but boxes still falls down.
The scale of the boxes is 1x1x1.
To note, interpolation does not affect the physics, itâs purely for visuals and changes the Transform only, not the body pose.
Right, so this shows the problem. Your description made it sound like they were not stable and were falling on top of each other, falling over etc. They are clearly being pushed sideways so that means the solver is pushing them away from each other meaning they are overlapping when you start the simulation.
You cannot place them numerically next to each other and consider this just touching; to the physics engine, theyâll be overlapping because the physics engine uses a contact offset (small gap) to ensure stability so they are considered touching defined by a distance of: https://docs.unity3d.com/ScriptReference/Physics-defaultContactOffset.html. In other words, theyâd never actually come to rest as youâre starting them; theyâd be slightly separated and then go to sleep.
This doesnât mean you should try setting this to zero to âsolveâ the problem. It means they should initially be at least this far apart from each other.
Try a single stack where each items is at least this far apart. Get that stable using the settings described previously then you can add more stacks next to each other, again, at least this distance apart.
Please note though, Iâm not a 3D physics dev but a 2D physics dev so this is a mostly guestimate on what is is going on here but the sideways movement indicates starting in an initial overlap state for sure.
Hm. So I used the grid tool set to 1 unit for all axis and copied them so that they are basically 0 to each other in all directions. Are you saying I need to move them in all directions in 0.01 or something to make them not interfere with each other on startup? This seems weirdâŚ
Yep, I never side only doing that would. I said all the boxes are likely overlapping. This obviously includes vertically.
Itâs just that the sudden âexplosiveâ separation isnât typically a stability issue but instead an instantanteous impulse where the solver is trying to separate things.
I just did a test with a prefab (box collider, rigidbody set as continuous dynamic) and it works if they are separated.
I tried this as a rough test script:
using UnityEngine;
public class Separate : MonoBehaviour
{
public GameObject Cube;
public int ColumnCount = 10;
public int ColumnStackCount = 8;
// Start is called before the first frame update
void Start()
{
var stride = 1f + Physics.defaultContactOffset;
for(var x = 0; x < ColumnCount; x++)
{
var basePos = Vector3.right * x * stride;
for(var y = 0; y < ColumnStackCount; y++)
{
Instantiate(Cube, basePos + Vector3.up * y * stride, Quaternion.identity);
}
}
}
}
That said, even without the extra offset I donât get the explosive effect you get, just a little more rocking until it settles i.e. if I do:
var stride = 1f;// + Physics.defaultContactOffset;
Note that if I increase the solver iterations, they donât sway at all and are rock solid.
Youâre talking over my head. I suck at this. I am getting compile errorsâŚ
Assets/Material/Separate.cs(3,14): error CS0101: The namespace ââ already contains a definition for âSeparateâ
Assets/Material/Separate.cs(10,10): error CS0111: Type âSeparateâ already defines a member called âStartâ with the same parameter types
ArgumentException: The Object you want to instantiate is null.
Okay, so your project worked and I cannot see what is different from mine. What does the the script actually do? Offset cubes just a tiny bit sides and up and down?
I would use this script but the problem is that I need all cubes to have different individual scripts, colors etc:)
Could you try to setup the same without a script and see what happens?
Itâs not supposed to be for anything other than showing you that it works.
I have no idea what that means. If I create these manually theyâll do exactly the same thing. It does matter how you create them.
Thereâs nothing wrong with being inexperienced but letâs not think that itâs how you created them that causes the problem so me doing more work for you wonât reveal anything. The script is super simple. Youâre not going to be able to create games without understand basic C# and writing scripts. Visual Scripting will only get you so far. Thereâs plenty of tutorials out there that will help you with this. I would start by looking at the Unity Learn site.
I think I can get quite far in my game development with visual scripting as I have already made some cool games:)
Of course Iâd like to learn the C# but I love to do 3D, make the concepts etc. Programming is so far too hard to get my head around. Also I think knowing that one needs to adjust things in the project settings for gravity stuff to work, is as little to do with C# as Visual Scripting:) Haha.
But anyway I redid everything and now it is somehow workingâŚI have no idea what the reason whyâŚJust happy that it worked!
Thanks for all the help:) It got me where I wanted!