private void DispenseObject(ClusterResource clusterResource) { if ((MaxObjectCount > 0) && (dispensedObjects.Count >= MaxObjectCount)) { DestroyOldestObject(); } Vector rotWithVariance = RotationOffset; if (hasRotationVariance) { rotWithVariance += new Vector(RotationVariance.X * RandomNegOneToOne(), RotationVariance.Y * RandomNegOneToOne(), RotationVariance.Z * RandomNegOneToOne()); } Quaternion rotation = Quaternion.FromEulerAngles(Mathf.RadiansPerDegree * rotWithVariance); Quaternion objectRotation = ObjectPrivate.Rotation; Vector position = PositionOffset; if (hasPositionVariance) { position += new Vector(PositionVariance.X * RandomNegOneToOne(), PositionVariance.Y * RandomNegOneToOne(), PositionVariance.Z * RandomNegOneToOne()); } Vector velocity = InitialLinearVelocity; if (hasLinearVelocityVariance) { velocity += new Vector(LinearVelocityVariance.X * RandomNegOneToOne(), LinearVelocityVariance.Y * RandomNegOneToOne(), LinearVelocityVariance.Z * RandomNegOneToOne()); } if (InheritMotion && (dispenserRigidBody != null)) { velocity += dispenserRigidBody.GetLinearVelocity(); } try { ScenePrivate.CreateClusterData dispensedObject = (ScenePrivate.CreateClusterData)WaitFor(ScenePrivate.CreateCluster, clusterResource, ObjectPrivate.Position + position.Rotate(objectRotation), ObjectPrivate.Rotation * rotation, velocity.Rotate(objectRotation)); if (hasInitialAngularVelocity) { RigidBodyComponent rb; if (dispensedObject.ClusterReference.GetObjectPrivates().FirstOrDefault().TryGetFirstComponent(out rb)) { if (rb.GetMotionType() != RigidBodyMotionType.MotionTypeStatic) { Vector angularVel = InitialAngularVelocity; if (hasAngularVelocityVariance) { angularVel += new Vector(AngularVelocityVariance.X * RandomNegOneToOne(), AngularVelocityVariance.Y * RandomNegOneToOne(), AngularVelocityVariance.Z * RandomNegOneToOne()); } if (InheritMotion && (dispenserRigidBody != null)) { angularVel += dispenserRigidBody.GetAngularVelocity(); } rb.SetAngularVelocity(angularVel); } } } dispensedObjects.AddLast(dispensedObject); } catch (ThrottleException) { // Throttled Log.Write(LogLevel.Warning, "DispenseObject throttle hit. No object created."); } }