private Vector3 GetVelocity(Vector3 enemyPos, CannonballBehavior projectile) { Vector3 direction = enemyPos - m_playerFiringPoint.position; float travelTime = (Mathf.Pow(direction.x, 2) + Mathf.Pow(direction.z, 2)) / Mathf.Pow(projectile.m_speed, 2); travelTime = Mathf.Sqrt(travelTime); Vector3 newVelocity = new Vector3(direction.x / travelTime, (direction.y / travelTime) - (Physics.gravity.y * travelTime / 2f), direction.z / travelTime); return(newVelocity); }
private void FireProjectile(Vector3 enemyPos) { GameObject cannonball = PoolManager.Instance.GetObject((int)Objects.CANNONBALL_L); cannonball.transform.position = m_playerFiringPoint.position; cannonball.SetActive(true); CannonballBehavior script = cannonball.GetComponent <CannonballBehavior>(); script.m_damage = m_damage; script.SetVelocity(GetVelocity(enemyPos, script)); }