Hi, I’m using some coroutines to avoid update whenever I can, but I noticed some inconsistencies in where my particles stop moving while doing some tests (dev’ing for android devices)
this is my coroutine to move an effect
IEnumerator MoveProjectile(float duration, GameObject enemy)
{
currentAttack.transform.position = SKT_Hand_R.transform.position;
Vector3 attackDir = (enemy.transform.position - SKT_Hand_R.position).normalized;
float startTime = Time.time;
while (Time.time < startTime + duration)
{
currentAttack.transform.position += attackDir * attackVelocity;
yield return null;
}
}
Ideally I would prefer the particle effect (the projectile being moved) to stop at the same position each time, but I noticed while testing that the difference in distance can be pretty substantial (if the “unit” is one player’s width, this projectile can stop moving anywhere from 1 unit to 3 units away)
I’m testing this on my pc, and I’m worried that on devices that are much slower, the distances at which these projectiles stop will be greater
Is there a better way to move a projectile and guarantee distance traveled? I’m guessing these differences in distance are due to floating point precision?
Thanks for any advice/pointers/suggestions