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. @Hellium
float gravity = 8; // this value increases over time
IEnumerator SimulateProjectile()
{
// Calculate distance to target
float target_Distance = Vector3.Distance(player.position, target.position);
// Calculate the velocity needed to throw the object to the target at specified angle.
float projectile_Velocity = target_Distance / (Mathf.Sin(2 * firingAngle * Mathf.Deg2Rad) / gravity);
// Extract the X Y componenent of the velocity
float Vx = Mathf.Sqrt(projectile_Velocity) * Mathf.Cos(firingAngle * Mathf.Deg2Rad);
float Vy = Mathf.Sqrt(projectile_Velocity) * Mathf.Sin(firingAngle * Mathf.Deg2Rad);
float elapse_time = 0;
while (player.position.y >= 3.3f)
{
player.Translate(Vx * Time.fixedDeltaTime, (Vy - (gravity * elapse_time)) * Time.fixedDeltaTime, 0);
elapse_time += Time.fixedDeltaTime;
yield return null;
}
}
↧