public void StopPull()
        {
            var oldPuller = _puller;

            if (oldPuller == null)
            {
                return;
            }

            _puller = null;

            if (ControlledComponent == null)
            {
                return;
            }

            ControlledComponent.WakeBody();

            var message = new PullStoppedMessage(this, oldPuller, ControlledComponent);

            oldPuller.Owner.SendMessage(null, message);
            ControlledComponent.Owner.SendMessage(null, message);

            ControlledComponent.TryRemoveController <PullController>();
        }
        public void TryMoveTo(EntityCoordinates from, EntityCoordinates to)
        {
            if (_puller == null || ControlledComponent == null)
            {
                return;
            }

            var entityManager = IoCManager.Resolve <IEntityManager>();

            if (!from.InRange(entityManager, to, SharedInteractionSystem.InteractionRange))
            {
                return;
            }

            ControlledComponent.WakeBody();

            var dist = _puller.Owner.Transform.Coordinates.Position - to.Position;

            if (Math.Sqrt(dist.LengthSquared) > DistBeforeStopPull ||
                Math.Sqrt(dist.LengthSquared) < 0.25f)
            {
                return;
            }

            _movingTo = to;
        }
Beispiel #3
0
        public override void UpdateAfterProcessing()
        {
            if (ControlledComponent == null)
            {
                return;
            }

            if (ControlledComponent.Owner.IsWeightless())
            {
                if (ActionBlockerSystem.CanMove(ControlledComponent.Owner) &&
                    ControlledComponent.IsColliding(Vector2.Zero, false))
                {
                    Stop();
                }

                return;
            }

            LinearVelocity *= Decay;

            if (LinearVelocity.Length < 0.001)
            {
                Stop();
            }
        }
Beispiel #4
0
        public override void UpdateAfterProcessing()
        {
            base.UpdateAfterProcessing();

            if (ControlledComponent == null || _movingTo == null)
            {
                return;
            }

            ControlledComponent.WakeBody();

            if ((ControlledComponent.Owner.Transform.WorldPosition - _lastKnownPosition).Length <= 0.05f)
            {
                _numTicksBlocked++;
            }
            else
            {
                _numTicksBlocked = 0;
            }

            _lastKnownPosition = ControlledComponent.Owner.Transform.WorldPosition;

            if ((ControlledComponent.Owner.Transform.WorldPosition - _movingTo.Value).Length <= 0.1f)
            {
                _movingTo = null;
            }

            if (_movingTo.HasValue)
            {
                var dist = (_lastKnownPosition - _movingTo.Value).Length;

                if (dist > _initialDist)
                {
                    _isMovingWrongDirection = true;
                }

                var diff = _movingTo.Value - ControlledComponent.Owner.Transform.WorldPosition;
                LinearVelocity = diff.Normalized * 5;
            }
            else
            {
                LinearVelocity = Vector2.Zero;
            }
        }
        public void StartPull(ICollidableComponent puller)
        {
            DebugTools.AssertNotNull(puller);

            if (_puller == puller)
            {
                return;
            }

            _puller = puller;

            if (ControlledComponent == null)
            {
                return;
            }

            ControlledComponent.WakeBody();

            var message = new PullStartedMessage(this, _puller, ControlledComponent);

            _puller.Owner.SendMessage(null, message);
            ControlledComponent.Owner.SendMessage(null, message);
        }
        public override void UpdateAfterProcessing()
        {
            if (ControlledComponent == null)
            {
                return;
            }

            if (_physicsManager.IsWeightless(ControlledComponent.Owner.Transform.Coordinates))
            {
                if (ControlledComponent.IsColliding(Vector2.Zero, false))
                {
                    Stop();
                }

                return;
            }

            LinearVelocity *= Decay;

            if (LinearVelocity.Length < 0.001)
            {
                Stop();
            }
        }
Beispiel #7
0
 public void StopPull()
 {
     _puller = null;
     ControlledComponent?.TryRemoveController <PullController>();
 }