private void SpawnExplosion(Fuze fuze) { if (fuze.ExplosionPrefab == null) { return; } var position = transform.position; if (fuze.IsRandomExplosion) { position = ownTarget.GetRandomPointOnTarget(); position = transform.TransformPoint(position); } Instantiate(fuze.ExplosionPrefab, position, transform.rotation); }
private void PhysicalizeMesh(Fuze fuze) { if (fuze.Debris == null) { return; } // Disable physics on the own ship to prevent weird physics forces from // spawning things inside each other. This also assumes that debris separation // is the very last thing that happens. GetComponent <Rigidbody>().isKinematic = true; var debris = fuze.Debris; debris.transform.SetParent(null); debris.SetActive(true); var meshes = fuze.Debris.GetComponentsInChildren <MeshRenderer>(); foreach (var mesh in meshes) { var collider = mesh.gameObject.AddComponent <MeshCollider>(); collider.convex = true; } var rigid = debris.AddComponent <Rigidbody>(); rigid.useGravity = false; rigid.ResetInertiaTensor(); rigid.ResetCenterOfMass(); rigid.mass = shipMass; rigid.angularVelocity = Random.insideUnitSphere * 3f * Mathf.Deg2Rad; rigid.velocity = (debris.transform.position - transform.position).normalized * 5f; rigid.drag = .02f; rigid.angularDrag = .1f; }