- Home /
Adding gravity to my gameobject causes lagg
I got a problem. When i add gravity to my prefab and click on play, everything gets slowed down.
The gameobjects won't fall in a normal way. ( it seems like they got some kind of delay, they drop down for a second and stops for a second, this repeat itself over and over again. )
The strange part is that this problem will only appear when my map of blocks is 30x30x1 (x,z,y) or higher.
var block : GameObject;
//Change to adjust the lenght = x and z
var worldWidth : uint = 30;
var worldHeight : uint = 30;
function Start () {
CreateWorld();
}
function Update () {
}
function CreateWorld() {
//Space between each block (x)
for(var x : uint =0; x<worldWidth; x+=1) {
//Space between each block (z)
for(var z : uint =0; z<worldHeight; z+=1) {
var block = Instantiate(block);
block.transform.position = new Vector3(this.transform.position.x + x, this.transform.position.y, this.transform.position.z + z);
}
}
}
This is the script i use, its Javascript.
Can someone please explain why it laggs so badly. Is it my script? has it to be in C#? I want to use it to make a floor out of cubes, those cubes will fall down when triggered by the player.
I hope you can help me
Kind regards, Hexer
Answer by IgorAherne · Jul 21, 2013 at 09:41 PM
1) check that the sizes of cubes are close to real ones, for example, car is 2 meters in length, etc.
2) Go to Project Settings - Time and check that Fixed time step is smaller or equal to 0.02
1) I tried to change the scale of the cubes and then i adjust the variable in the script. When i click on start my Unity crashes.
2) Adjusting the Fixed timestep doesn't work. It's on 0.02 but when i try to change it to 0.01 everything get even worse.
I have found that adjusting the timescale(1) to timescale(0,5) helps abit. but it makes the moment of my character slow.
Never$$anonymous$$d, thanks for your answer. it helped me out. It is still not that smooth but i think i can change that.