- Home /
Change directions, at random times?
"Yes, a constant movement would be Ideal. I would just like the object to invert its direction on the x axis at random times."
Thanks for future help!
Answer by Fattie · Sep 13, 2012 at 05:42 AM
Now that you've explained what you actually want, here it is
the critical thing is you want the gaps in time to be random. Here's how to do it.
to change direction, it's velocity = -velocity;
// put this next line in say Start() ...
Invoke( "NewFunDirection", Random.Range(0.5,2.0) );
function NewFunDirection()
{
rigidbody.velocity = -rigidbody.velocity;
Invoke( "NewFunDirection", Random.Range(0.5,2.0) );
}
I would think AddForce is about to kick the object and then velocity drops down. I may be wrong but I would guess he wants a constant movement.
Yes, a constant movement would be Ideal. I would just like the object to invert its direction on the x axis at random times.
NP. there are three or four typical patterns for "gap, always the same but random" versus "each gap is random" versus "a fixed overall time, but the gaps in-between are jiggled randomly" and so on and on ...