private void OnCollect(Garbage garbage)
 {
     SceneSystem.SceneInstance.RootScene.Entities.Remove(garbage.Entity);
     Team.OnGarbageCollected(garbage);
     CollectEffect.ParticleSystem.Play();
     CollectEffect.ParticleSystem.ResetSimulation();
 }
Example #2
0
 internal void OnGarbageCollected(Garbage garbage)
 {
     Points++;
 }
Example #3
0
        public void UpdateGrab()
        {
            float   closestDistanceSquared = float.MaxValue;
            Vector3 closestDelta           = Vector3.Zero;
            Garbage closest = null;

            foreach (var collision in Rigidbody.Collisions)
            {
                var a = collision.ColliderA;
                var b = collision.ColliderB;
                if (b == Rigidbody)
                {
                    Utilities.Swap(ref a, ref b);
                }
                var garbage = b.Entity.Get <Garbage>();
                if (garbage == null)
                {
                    continue;
                }
                if (!SelectTarget(garbage))
                {
                    continue;
                }
                Vector3 d = b.Entity.Transform.WorldMatrix.TranslationVector -
                            Entity.Transform.WorldMatrix.TranslationVector;
                float l = d.LengthSquared();
                if (l < closestDistanceSquared)
                {
                    closestDistanceSquared = l;
                    closestDelta           = d;
                    closest = garbage;
                }
            }

            if (closest != null)
            {
                float l = closestDelta.Length();

                float r = l / PullFarFalloffRadius;
                r = MathUtil.Clamp(r, 0, 1);

                closestDelta.Z = 0.0f;
                Vector3 direction = -Vector3.Normalize(closestDelta);

                Vector3 newVelocity  = closest.Rigidbody.LinearVelocity;
                float   currentSpeed = Vector3.Dot(direction, newVelocity);

                float pullStrength = 1 - r;
                float addSpeed     = pullStrength * PullStrengthMultiplier *
                                     (float)Game.UpdateTime.Elapsed.TotalSeconds;
                if (currentSpeed < MaxSpeed)
                {
                    newVelocity += direction * addSpeed;
                }

                float length = newVelocity.Length();
                if (length > 0)
                {
                    float brakeStrength = r / BrakeRatio;
                    brakeStrength = MathUtil.Clamp(brakeStrength, 0, 1);
                    brakeStrength = 1 - brakeStrength;
                    if (brakeStrength > 0)
                    {
                        length -= brakeStrength * BrakeStrengthMultiplier * (float)Game.UpdateTime.Elapsed.TotalSeconds;
                        if (length < 0)
                        {
                            length = 0;
                        }
                        newVelocity.Normalize();
                        newVelocity *= length;
                    }
                }

                closest.Rigidbody.LinearVelocity = newVelocity;
            }

            LastPullTarget = closest;
        }
Example #4
0
 protected virtual bool SelectTarget(Garbage garbage)
 {
     return(true);
 }