- Home /
Transform.Translate is not slowing down...?
I have in my void function a while/for loop with a transform.translate method but When I'am changing the speed multiplier or adding Time.deltatime my character won't slow down.. Instead he will just cover a smaller distance. Can it only work in fixed update? Iam using btw Rigidbody.
void moving(){
for (int i = 0; i < 1000; i++)
transform.Translate(Vector3.forward * speed * Time.deltaTime);
}
void fixedupdate(){ moving(); } //will work void eventriggerfunction(){moving(); } // won't work
I dont understand, your loop is basically just doing Translate 1000x times which would be as simple as
void moving(){
transform.Translate(Vector3.forward * speed * Time.deltaTime * 1000);
}
But I'm not sure why you aren't just doing something like
void $$anonymous$$ove()
{
Vector3 velocity = transform.forward * speed * Time.deltaTime;
velocity.y = rigidBody.velocity.y;
rigidBody.velocity = velocity;
}
why will transform.translate multiplied by 1000 ins$$anonymous$$d of letting the character move each (1000) frames by some? Should the time it takes to fill out that loop not result in slower speed ins$$anonymous$$d of multiplying it right away by 1000.@RobAnthem
Btw if I'am putting the void move in fixedupdate it will work why is that? void fixedupdate(){ move();} works. void eventriggerfunction(){ move();} won't work. Thanks in advance.
Answer by Masterio · Mar 14, 2019 at 09:54 AM
If You are using Rigidbody simply use the 'drag' option:
https://docs.unity3d.com/ScriptReference/Rigidbody-drag.html
Greater value gives more slow down.