- Home /
Question by
yeahservice · Oct 26, 2016 at 10:30 PM ·
movementfluid
Fluid movement with short waypoints
Hi,
I have an external module giving me current positions for my objects. The whole system is working fine so far but I have the problem that the movement is very choppy. The positions that I get regularly are really close to each other:
old position x:-25.5098 y: -41.2096 new position x: -26.5232 y: -41.269
My update function for the objects looks like this:
float step = Speed * Time.deltaTime;
Vector3 targetPoint = new Vector3(X, transform.position.y, Z);
if (Vector3.Distance(transform.position, targetPoint) < 0.5f)
{
anim.SetFloat("Speed", 0.0f);
}
else
{
transform.LookAt(targetPoint);
transform.position = Vector3.MoveTowards(transform.position, targetPoint, step);
anim.SetFloat("Speed", Speed);
}
With this the objects take 1 step, wait a bit and take another step, and so on. What would be the correct approach to get a fluid movement with this system.
Comment