Exemplo n.º 1
0
        public bool CheckForPoints(out PointHitCheck hit)
        {
            hit = null;

            Collider[] colliders = Physics.OverlapSphere(transform.position, radius * 2);
            foreach (Collider collider in colliders)
            {
                AssemblerPoint point = collider.GetComponent <AssemblerPoint>();
                if (point != null && point.isConnected == false)
                {
                    if (point.ID == ID && point.comp != comp && (point.comp.connected || point.comp.core)) //attach conditions
                    {
                        hit = new PointHitCheck(Vector3.Distance(transform.position, point.transform.position), point);
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        private void Update()
        {
            if (faker)
            {
                return;
            }

            bool detached = true;

            for (int pointIndex = 0; pointIndex < points.Length; pointIndex++)
            {
                if (core == false)
                {
                    pointColliders[pointIndex].connectable = (rb == null);

                    if (pointColliders[pointIndex].connected)
                    {
                        detached = false;
                    }
                }
                else
                {
                    detached = false;
                    pointColliders[pointIndex].connectable = true;
                }
            }

            if (core == false)
            {
                if (detached)
                {
                    if (connected)
                    {
                        Detach();
                    }
                }

                if (interactable.attachedToHand) // If i'm being held
                {
                    if (connected)
                    {
                        if (dismantle)
                        {
                            Detach();
                        }
                        else
                        {
                            //KnucklesPhysicalInteraction kpi = ki.heldBy;
                            //kpi.ForceGrab(coreComp.ki);
                        }
                    }

                    rb.isKinematic = false;
                    PointHitCheck[] hits = new PointHitCheck[points.Length];
                    for (int i = 0; i < points.Length; i++)
                    {
                        PointHitCheck hit;
                        if (pointColliders[i].CheckForPoints(out hit)) // check if each point is touching another object's
                        {
                            hits[i] = (hit);
                        }
                    }
                    attachPoint = FindNearest(hits);
                    if (attachPoint != null)
                    {
                        RenderSnap();
                    }
                }
                else
                {
                    if (wasgrab)
                    {
                        if (attachPoint != null)
                        {
                            Attach();
                            attachPoint = null;
                        }
                    }
                }

                wasgrab = interactable.attachedToHand;
            }
        }