Example #1
0
        void ConnectToRope(UseContext args)
        {
            var ropeLinkPos = TractorRopeLink.gameObject.transform.position;

            foreach (Rigidbody body in GameObjectExt.GetNearbyObjects <Rigidbody>(ropeLinkPos, 0.7f,
                                                                                  GameObjectExt.GetLayerMask("Objects") | GameObjectExt.GetLayerMask("StructurePlatform") | GameObjectExt.GetLayerMask("Structure")

                                                                                  ))
            {
                var   go = body.gameObject;
                float ps = 322.0f;
                float mf = 322.0f;
                ps = mf = 1000.0f;
                float pd = 111.0f;

                var hj = CreateJoint(body, m_Tractor.GetComponent <Rigidbody>(), ps, mf, pd);
                // ore always connects in the center
                if (go.name.ToLower().Contains("ore"))
                {
                    hj.autoConfigureConnectedAnchor = false;
                    hj.connectedAnchor = Vector3.zero;
                    hj.targetPosition  = Vector3.zero;
                }
                else
                {
                    hj.autoConfigureConnectedAnchor = false;
                    hj.anchor         = go.transform.InverseTransformPoint(args.m_TargetPos);
                    hj.targetPosition = Vector3.zero;
                }

                if (TractorRopeLink.ConnectJoint(hj))
                {
                    return;
                }
            }

            // Couldn't connect, see if we assume it was a refund
            TractorRopeLink.m_Rope.CheckRefund(TractorRopeLink);
        }
Example #2
0
        bool InternalBeginUse(UseContext args)
        {
            m_UsingStrongBeam = args.m_ButtonPressed != 0;
            m_Tractor         = null;

            var target = args.m_TargetPos;

            if ((target - args.m_OriginPos).magnitude > MaxUseDistance)
            {
                args.m_ShowStatusMessage = "Target position too far away to tractor";
                return(false);
            }
            var ropes = GameObjectExt.GetNearbyObjects <Rigidbody>(target, 1.0f, GameObjectExt.GetLayerMask("Rope"));

            ropes.Sort((a, b) =>
            {
                return(a.transform.position.DistanceTo(target).CompareTo(b.transform.position.DistanceTo(target)));
            }
                       );

            var bodies = GameObjectExt.GetNearbyObjects <Rigidbody>(target, 1.0f,
                                                                    GameObjectExt.GetLayerMask("Objects") |
                                                                    GameObjectExt.GetLayerMask("Rope") |
                                                                    GameObjectExt.GetLayerMask("Trees")
                                                                    );

            bodies.Sort((a, b) =>
            {
                return(a.transform.position.DistanceTo(target).CompareTo(b.transform.position.DistanceTo(target)));
            }
                        );
            foreach (var rope in ropes)
            {
                bodies.Insert(0, rope);
            }

            foreach (Rigidbody body in bodies)
            {
                var link = body.gameObject.GetComponent <RopeLink>();
                if (link != null && !link.CanTractor)
                {
                    continue;
                }

                // whelp we're not moving this thing
                if (body.isKinematic)
                {
                    continue;
                }

                m_Tractor            = body.gameObject;
                m_TractorLocalOffset = body.gameObject.transform.InverseTransformPoint(args.m_TargetPos);

                if (TractorRopeLink != null)
                {
                    TractorRopeLink.ConnectJoint(null);
                }

                return(true);
            }

            args.m_ShowStatusMessage = "Tractor must be used on loose object";
            return(false);
        }