- Home /
transform.Translate by Time.deltaTime
I have 4 objects, Blue, Red, Yellow, Green.
They all have this line of code:
transform.Translate(Vector3.forward * Time.deltaTime*5, Space.World);
However they all seem to move at different speeds...Yellow slowest, then Red, then Blue and Red much faster.
I need all the object to move at exactly the same speed so I thought this would be perfect, but as it is they end up colliding with each other and making a mess.
They are all rigid bodies with a mass of 1.
Any suggestions would much appreciated.
That will result in the same speed outside of other factors. $$anonymous$$ass is irrelevant when directly translating them.
It would appear it is an issue when importing from 3DS $$anonymous$$ax. The objects are at different scales. The bigger objects move faster even though they are the same size in Unity. The box colliders on them were
Yellow = 2.6 x 6 x 2.2 Red = 23 x 15 x 17 Blue = 1 x 1 x 1
Like I said when they are in Unity they are all the same relative size but these weird scales must be something to do with it.
Answer by Bunny83 · Feb 12, 2012 at 02:12 AM
Ok, i just tried many things. First i thougt you might have different parents for each object and everyone with a different scale. However that has no influence on the speed since you move in world-space.
To cut it short: No matter what i do to the setup, i can't make them move at different speeds. The only thing left over is that you have another script that moves the object. Since it's a rigidbody it's possible that you set a velocity or a one-time AddForce (which is pretty much the same) somewhere. Check the velocity of all rigidbodies, they should be (0,0,0) since you move them without physics.
When they are Rigidbodies you might just want to set a velocity?
// Unityscript (Javascript)
function Start()
{
rigidbody.velocity = Vector3(0,0,5);
}
This will make the object move along the positive z-axis at a speed of 5, just like your piece of code above. Note: that only works for non-kinematic Rigidbodies. If you have a kinematic RB you have to move it "manually" like you already do.
Hey, thanks for taking the time to have a look into this. It was only the one line of code that was for the movement. I have shown this problem to my Uni lecturer and he is baffled by it too.
The only difference is the relative size of the objects. I have made them all 1 x 1 x 1 cubes from within unity and it is working fine, but as soon as I bring in the 3DS models it is going out of sync.
I will try out this suggestion when I get in from Uni and see how it goes.
Answer by Berenger · Feb 12, 2012 at 02:07 AM
If they have gravity, it might come from the friction. Are they kinematic ? I don't think the scale before or after the import have any effect.