bug on iOS builds only. transform.translate doesn’t work properly

Updated on September 29, 2018 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on September 29, 2018

Hi, i am using a script which simulates a projectile, with coroutine. Script works perfectly on Unity Editor, Windows build, Android build, except on iOS builds. I have a public float called gravity. Depending on it’s value, changes the velocity of projectile. Problem is that on iOS builds, value of gravity changes based on conditions on the script, but still, velocity of projectile remains same. Following is the part of script where i simulate projectile.

  1. float gravity = 8; // this value increases over time
  2. IEnumerator SimulateProjectile()
  3. {
  4. // Calculate distance to target
  5. float target_Distance = Vector3.Distance(player.position, target.position);
  6. // Calculate the velocity needed to throw the object to the target at specified angle.
  7. float projectile_Velocity = target_Distance / (Mathf.Sin(2 * firingAngle * Mathf.Deg2Rad) / gravity);
  8. // Extract the X Y componenent of the velocity
  9. float Vx = Mathf.Sqrt(projectile_Velocity) * Mathf.Cos(firingAngle * Mathf.Deg2Rad);
  10. float Vy = Mathf.Sqrt(projectile_Velocity) * Mathf.Sin(firingAngle * Mathf.Deg2Rad);
  11. float elapse_time = 0;
  12. while (player.position.y >= 3.3f)
  13. {
  14. player.Translate(Vx * Time.fixedDeltaTime, (Vy - (gravity * elapse_time)) * Time.fixedDeltaTime, 0);
  15. elapse_time += Time.fixedDeltaTime;
  16. yield return null;
  17. }
  18. }
  • Liked by
Reply