Exemplo n.º 1
0
        private void StabilizeTargetedObject()
        {
            TargetedObject.SetLinearVelocity(Vector2.Zero);

            m_distanceJointObject = Game.CreateObject("InvisibleBlockSmall");
            m_distanceJointObject.SetBodyType(BodyType.Dynamic);

            m_distanceJoint = (IObjectDistanceJoint)Game.CreateObject("DistanceJoint");
            m_distanceJoint.SetLineVisual(LineVisual.None);
            m_distanceJoint.SetLengthType(DistanceJointLengthType.Fixed);

            m_targetedObjectJoint = (IObjectTargetObjectJoint)Game.CreateObject("TargetObjectJoint");

            var targetedObjPosition = TargetedObject.GetAABB().Center;

            m_distanceJointObject.SetWorldPosition(targetedObjPosition);
            TargetedObject.SetWorldPosition(targetedObjPosition);
            m_pullJoint.SetWorldPosition(targetedObjPosition);
            m_distanceJoint.SetWorldPosition(targetedObjPosition);
            // if DistanceJoint and TargetObjectJoint is at the same position, weird things may happen
            // uncomment the part below to stop it
            m_targetedObjectJoint.SetWorldPosition(m_distanceJointObject.GetWorldPosition() /* - Vector2.UnitY*/);

            m_pullJoint.SetTargetObject(m_distanceJointObject);
            m_distanceJoint.SetTargetObject(m_distanceJointObject);
            m_distanceJoint.SetTargetObjectJoint(m_targetedObjectJoint);
            m_targetedObjectJoint.SetTargetObject(TargetedObject);
            m_pullJoint.SetForce(15);

            IsTargetedObjectStabilized = true;
        }
Exemplo n.º 2
0
        public override void Update(float elapsed)
        {
            base.Update(elapsed);

            if (Owner.IsManualAiming)
            {
                var holdPosition = GetHoldPosition(true);
                m_invisibleMagnet.SetWorldPosition(holdPosition);
                // m_invisibleMagnet is a static object so the corresponding TargetObjectJoint need to be moved manually too
                m_magnetJoint.SetWorldPosition(holdPosition);

                if (TargetedObject != null)
                {
                    TryStabilizeTargetedObject(holdPosition);
                }

                if (Game.IsEditorTest)
                {
                    var scanLine = GetScanLine();

                    Game.DrawLine(scanLine[0], scanLine[1]);
                    Game.DrawCircle(holdPosition, .5f, Color.Red);

                    //Game.DrawCircle(position, .5f, Color.Blue);
                    //Game.DrawLine(position, position + direction * 6, Color.Yellow);
                    //Game.DrawArea(m_pullJoint.GetAABB(), Color.Cyan);
                    //Game.DrawArea(m_magnetJoint.GetAABB(), Color.Magenta);

                    if (TargetedObject != null)
                    {
                        Game.DrawArea(TargetedObject.GetAABB(), Color.Blue);
                    }

                    //if (m_distanceJointObject != null)
                    //    Game.DrawArea(m_distanceJointObject.GetAABB(), Color.Green);

                    var to = m_pullJoint.GetTargetObject();
                    if (to != null)
                    {
                        Game.DrawArea(to.GetAABB(), Color.Yellow);
                    }
                }
            }
            else
            {
                if (IsTargetedObjectStabilized || TargetedObject != null)
                {
                    StopStabilizingTargetedObject();

                    m_invisibleMagnet.SetWorldPosition(FarAwayPosition);
                    m_magnetJoint.SetWorldPosition(FarAwayPosition);
                }
            }
        }
Exemplo n.º 3
0
        private void TryStabilizeTargetedObject(Vector2 holdPosition)
        {
            var results        = RayCastTargetedObject(false);
            var stabilizedZone = GetStabilizedZone(holdPosition);

            Game.DrawArea(stabilizedZone, Color.Green);

            var targetedObjectFound = false;
            var targetHitbox        = TargetedObject.GetAABB();

            if (stabilizedZone.Intersects(targetHitbox))
            {
                targetedObjectFound = true;
            }

            foreach (var result in results)
            {
                if (result.HitObject == null)
                {
                    continue;
                }

                if (result.HitObject.UniqueID == TargetedObject.UniqueID)
                {
                    targetedObjectFound = true;

                    if (stabilizedZone.Intersects(targetHitbox))
                    {
                        if (!IsTargetedObjectStabilized)
                        {
                            StabilizeTargetedObject();
                            IsTargetedObjectStabilized = true;
                        }
                    }
                    break;
                }
            }

            if (!targetedObjectFound)
            {
                StopStabilizingTargetedObject();
            }
            else
            {
                var player = ScriptHelper.CastPlayer(TargetedObject);
                if (player != null && !player.IsStaggering)
                {
                    // Not sure why StaggerInfinite is not infinite!
                    player.AddCommand(new PlayerCommand(PlayerCommandType.StaggerInfinite));
                }
            }
        }
Exemplo n.º 4
0
        public Vector2 GetHoldPosition(bool useOffset)
        {
            var offset = 0f;

            if (TargetedObject != null && useOffset)
            {
                var hitbox = TargetedObject.GetAABB();
                var length = Math.Max(hitbox.Width, hitbox.Height);
                offset = length / 2f;
            }

            Vector2 position, direction;

            Owner.GetWeaponMuzzleInfo(out position, out direction);

            return(position + direction * (6 + offset));
        }
Exemplo n.º 5
0
        protected override void Update(float elapsed)
        {
            base.Update(elapsed);

            if (TargetedObject == null)
            {
                CheckIfCollide();
            }

            if (TargetedObject != null)
            {
                Game.DrawArea(TargetedObject.GetAABB(), Color.Red);
            }
            if (TargetedPlayer != null)
            {
                if (TargetedPlayer.IsOnGround)
                {
                    if (m_weldJoint != null)
                    {
                        Instance.SetBodyType(BodyType.Static);
                        m_weldJoint.Remove();
                        m_weldJoint = null;
                    }

                    if (TargetedPlayer.IsCrouching)
                    {
                        Instance.SetWorldPosition(TargetedPlayer.GetWorldPosition() - m_relPlayerPosition - Vector2.UnitY * 5);
                    }
                    else if (TargetedPlayer.IsRolling)
                    {
                        Instance.SetWorldPosition(TargetedPlayer.GetAABB().Center);
                    }
                    else
                    {
                        Instance.SetWorldPosition(TargetedPlayer.GetWorldPosition() - m_relPlayerPosition);
                    }
                }
                else if (TargetedPlayer.IsInMidAir) // cannot track position accurately when player is in mid air
                {
                    if (m_weldJoint == null)
                    {
                        Instance.SetBodyType(BodyType.Dynamic);
                        m_weldJoint = (IObjectWeldJoint)Game.CreateObject("WeldJoint");
                        m_weldJoint.SetWorldPosition(Instance.GetWorldPosition());
                        m_weldJoint.SetTargetObjects(new List <IObject>()
                        {
                            Instance, TargetedPlayer
                        });
                    }
                }
            }

            if (m_timeElasped != 0 && ScriptHelper.IsElapsed(m_timeElasped, 2000))
            {
                if (m_weldJoint != null)
                {
                    m_weldJoint.Remove();
                }
                DealExplosionDamage();
                Instance.Destroy();
            }
        }