private void OnDestroy() { world.Dispose(); for (int i = 0; i < particles.Length; ++i) { if (particles[i] != null) { particles[i].Dispose(); particles[i] = null; } if (platforms[i] != null) { platforms[i].Dispose(); platforms[i] = null; } } if (blobForceGenerator != null) { blobForceGenerator.Dispose(); blobForceGenerator = null; } }
private void Start() { blobForceGenerator = new BlobForceGenerator() { particles = particles, maximumForceToPullTogether = 10f, maximumForceToPushApart = 10f, maximumForceToFloat = 2f, minNaturalDistance = partcleRadius * 0.7f, maxNaturalDistance = partcleRadius * 1.4f, maxDistance = partcleRadius * 2.1f }; for (int i = 0; i < 5; ++i) { particles[i] = new PhysicsEngineForFun.Particle() { velocity = new PhysicsEngineForFun.Vector3(0, 0, 0), position = new PhysicsEngineForFun.Vector3(Random.Range(2 * i - 5, 2 * i + -3), 3, 0), acceleration = new PhysicsEngineForFun.Vector3(0, -2f, 0), damping = 0.2f }; particles[i].SetMass(0.2f); particles[i].ClearAccumulator(); world.particles.Add(particles[i]); platforms[i] = new Platform() { PointInPlatform = Vector3.zero, Normal = Vector3.up, ParticleRadius = partcleRadius, CheckParticle = particles[i] }; world.registry.Add(particles[i], blobForceGenerator); world.contactGenerators.Add(platforms[i]); } }