void OnTriggerEnter(Collider other) { //Debug.Log(name + " OnCollisionEnter " + other.name); #if UNITY_MFG && UNITY_EDITOR //we don't have FluidSurface in WebPlayer FluidSurface fluid = other.GetComponent <FluidSurface>(); if (fluid != null) { WaterVolume = other; fluid.AddDropletAtWorldPos(Transform.position, 0.5f, +0.5f); ProjectileManager.Instance.PlayGrenadeHitSound(other.gameObject.layer, Transform.position); CombatEffectsManager.Instance.PlayHitEffect(other.gameObject, Transform.position, Vector3.up, E_ProjectileType.None, Owner != null && Owner.IsOwner); } #endif }
public virtual void ProjectileUpdate() { MFDebugUtils.Assert(IsFinished() == false); Timer += Time.deltaTime; if (Hit == true) { return; } if (Transform.localScale.z != 1) { Transform.localScale = new Vector3(1, 1, Mathf.Min(1, Transform.localScale.z + Time.deltaTime * 8)); } float dist = Settings.Speed * Time.deltaTime; Vector3 newPos = Pos + Dir * dist; RaycastHit[] hits = Physics.RaycastAll(Pos, Dir, dist, RayCastMask); if (hits.Length > 1) { System.Array.Sort(hits, CollisionUtils.CompareHits); } foreach (RaycastHit hit in hits) { //Debug.Log (Time.timeSinceLevelLoad + "Test: " + hit.transform.name); if (hit.transform == Settings.IgnoreTransform) { continue; } //skip the Owner of this shot when his HitZone got hit HitZone zone = hit.transform.GetComponent <HitZone>(); if (zone && (zone.HitZoneOwner is AgentHuman) && (zone.HitZoneOwner as AgentHuman).transform == Settings.IgnoreTransform) { continue; } //Debug.Log (Time.timeSinceLevelLoad + "HIT: " + hit.transform.name); // Debug.DrawLine(Transform.position, Transform.position + hit.normal, Color.blue, 4.0f); // Debug.DrawLine(Transform.position, hit.point, Color.red, 3.0f); Transform.position = hit.point; //HACK The projectile belongs to the "Default" collision layer. //This is probably bug but we do not want to modify the data at the moment. //The only chance now is to ignore such hits if (hit.transform.gameObject.name.StartsWith("Projectile")) { continue; } if (!ValidateHitAgainstEnemy(hit)) { continue; } hit.transform.SendMessage("OnProjectileHit", this, SendMessageOptions.DontRequireReceiver); if (ignoreThisHit) { ignoreThisHit = false; continue; } if (uLink.Network.isClient) { #if UNITY_MFG && UNITY_EDITOR //we don't have FluidSurface in WebPlayer FluidSurface fluid = hit.collider.GetComponent <FluidSurface>(); if (fluid != null) { fluid.AddDropletAtWorldPos(hit.point, 0.3f, 0.15f); } #endif // else if (hit.rigidbody) // { // // TODO: potrebujem poladit korektni hodnotu impulzu per-zbran // float force = Vector3.Dot(-hit.normal,Transform.forward) * 30; // // hit.rigidbody.AddForceAtPosition(Transform.forward * force,hit.point); // } } if (hit.collider.isTrigger) { continue; } newPos = hit.point; if (ricochetThisHit) { ricochetThisHit = false; Transform.forward = hit.normal; m_Forward = hit.normal; if (spawnHitEffects) { PlayHitSound(29); CombatEffectsManager.Instance.PlayHitEffect(hit.transform.gameObject, 29, hit.point, hit.normal, ProjectileType, Agent != null && Agent.IsOwner); } if ((m_ProjectileTrail != null) && UseTrail) { m_ProjectileTrail.AddTrailPos(newPos); } } else { Hit = true; if (spawnHitEffects) { PlayHitSound(hit.transform.gameObject.layer); CombatEffectsManager.Instance.PlayHitEffect(hit.transform.gameObject, hit.transform.gameObject.layer, hit.point, hit.normal, ProjectileType, Agent != null && Agent.IsOwner); } } if (GetComponent <Renderer>() != null) { GetComponent <Renderer>().enabled = false; } break; } Transform.position = newPos; if ((m_ProjectileTrail != null) && (UseTrail == true)) { m_ProjectileTrail.UpdateTrailPos(newPos); } }