Hi, is there a way ( or is there a script ) to move an object from point A to point B with random movement(like an insect)?
Thanks in advance!
Hi, is there a way ( or is there a script ) to move an object from point A to point B with random movement(like an insect)?
Thanks in advance!
There are any number of ways you could achieve this - it’s the kind of open-ended question that might make a good assignment for a beginner coding task!
Here’s one way that springs to mind:
Another method:
hope these give some inspiration!
Thanks duck, this will help!
someone can tell me why this little piece of simple code doesn’t work?
protected void Update()
{
if (c)
{
rVal = UnityEngine.Random.Range(-45f, 45f);
c = false;
oldQ = transform.localRotation;
}
transform.rotation = Quaternion.Lerp(oldQ, Quaternion.Euler(0, rVal, 0), Time.time * RotationSpeed);
}
it only work the first time i lunch it, then the interpolation stop.
It’s because you’re using Time.time instead of Time.deltaTime.
Time.time gives your the number of seconds elapsed since the project started playing.
Time.deltaTime gives you the amount of time elapsed since the last frame.
To get useful results from any Lerp command, you need to feed in values from 0 to 1 as the 3rd parameter. Lerp returns a value somewhere between the Min and Max, depending on where between 0 and 1 the 3rd parameter is.
If you use Time.time, your values will quickly exceed 1, and therefore the output is just clamped at the maximum value.
Hope this helps you sort it out.
:shock: how could i be so idiot! i didn’t notice the Time.time sorry.thanks for sharing your time again duck. ![]()
Also, search UnitySteer and take a look at the Wander steering method.