Ejemplo 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);
        }
Ejemplo n.º 2
0
        private AssemblerPoint FindNearest(PointHitCheck[] hits)
        {
            AssemblerPoint nearestPoint    = null;
            float          closestDistance = Mathf.Infinity;

            for (int pointIndex = 0; pointIndex < points.Length; pointIndex++)
            {
                if (hits[pointIndex] != null)
                {
                    if (hits[pointIndex].dist < closestDistance)
                    {
                        closestDistance = hits[pointIndex].dist;
                        nearestPoint    = hits[pointIndex].point;
                        m_attachPt      = pointColliders[pointIndex];
                    }
                }
            }

            return(nearestPoint);
        }
Ejemplo n.º 3
0
 public void DetachPoint()
 {
     connected   = null;
     isConnected = false;
 }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
0
 public PointHitCheck(float hitDistance, AssemblerPoint hitPoint)
 {
     dist  = hitDistance;
     point = hitPoint;
 }