- Home /
Vibrating GameObjects
I'm creating my first game and I have a problem. The game is about building highest tower possible with small boxes. They are moving and you need to click somewhere in the window in right time to place them right. You have small tolerance. If you place tile within the tolerance limit, the box will align perfectly with the previous one. The problem is, that even if you place it right (you have combo), the physics mess it up.
If the stack of boxes is too high, it starts vibrating and tilting. I included a link to the video, to make it clear. Boxes will always align to the position of the previous one, because of very high tolerance (for testing purposes). I also tried to align boxes to x = 0 and z = 0 , but it didn't work. Down below is also code (C#) that aligns boxes and adds Rigidbody to them in the right moment.
I apologize for my bad English.
Thank you for your answers.
private void PolozKostku()
{
/*
StandardniPozice = standardPosition
odchylka = offset
pohybPoOseX = isMovingOnX
stoh = stack
stohIndex = stackIndex
celkovyPocetKostek = numberOfBoxes
*/
Kombo(); // calling function, that align the box
// switching axis on which is box moving
if (pohybPoOseX == true) pohybPoOseX = false;
else pohybPoOseX = true;
// adding Rigidbody
body = stoh[stohIndex].AddComponent<Rigidbody>();
body.mass = 1;
}
private void Kombo()
{
if (kombo)
{
if ((StandardniPozice().x <= odchylka && pohybPoOseX == true) ||
(StandardniPozice().x <= -(odchylka) && pohybPoOseX == true)
|| (StandardniPozice().z <= odchylka && pohybPoOseX == false) ||
(StandardniPozice().z <= -(odchylka) && pohybPoOseX == false))
{
stoh[stohIndex].transform.position = new Vector3(StandardniPozice(1).x, celkovyPocetKostek - 0.5f, StandardniPozice(1).z);
}
else kombo = false;
}
}