MoveAlign() public static méthode

public static MoveAlign ( Transform source, Transform childNode, RaycastHit hit, Quaternion adjust ) : void
source Transform
childNode Transform
hit RaycastHit
adjust Quaternion
Résultat void
Exemple #1
0
 public void FixedUpdate()
 {
     if (syncGrab)
     {
         KAS_Shared.MoveAlign(this.part.transform, partNode.nodeTransform, evaNodeTransform);
         this.part.rigidbody.velocity = FlightGlobals.ActiveVessel.rootPart.rigidbody.velocity;
     }
 }
Exemple #2
0
        public void UpdatePointer()
        {
            if (!running)
            {
                if (pointer)
                {
                    UnityEngine.Object.Destroy(pointer);
                }
                return;
            }

            //Cast ray
            Ray        ray = FlightCamera.fetch.mainCamera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (!Physics.Raycast(ray, out hit, 500, 557059))
            {
                if (pointer)
                {
                    UnityEngine.Object.Destroy(pointer);
                }
                return;
            }

            //Create pointer if needed
            if (!pointer)
            {
                GameObject modelGo = partToAttach.FindModelTransform("model").gameObject;
                pointer = Mesh.Instantiate(modelGo) as GameObject;
                foreach (Collider col in pointer.GetComponentsInChildren <Collider>())
                {
                    UnityEngine.Object.Destroy(col);
                }

                allModelMr = new List <MeshRenderer>();
                // Remove attached tube mesh renderer if any
                List <MeshRenderer> tmpAllModelMr = new List <MeshRenderer>(pointer.GetComponentsInChildren <MeshRenderer>() as MeshRenderer[]);
                foreach (MeshRenderer mr in tmpAllModelMr)
                {
                    if (mr.name == "KAStube" || mr.name == "KASsrcSphere" || mr.name == "KASsrcTube" || mr.name == "KAStgtSphere" || mr.name == "KAStgtTube")
                    {
                        Destroy(mr);
                        continue;
                    }
                    allModelMr.Add(mr);
                    mr.material = new Material(Shader.Find("Transparent/Diffuse"));
                }
                pointerNodeTransform               = new GameObject("KASPointerPartNode").transform;
                pointerNodeTransform.parent        = pointer.transform;
                pointerNodeTransform.localPosition = partToAttach.srfAttachNode.position;
                pointerNodeTransform.localRotation = Quaternion.Inverse(Quaternion.LookRotation(partToAttach.srfAttachNode.orientation, Vector3.up));
            }

            //Set default color
            Color color = Color.green;

            // Check if object is valid
            bool      isValidObj = false;
            Part      hitPart    = null;
            KerbalEVA hitEva     = null;

            if (hit.rigidbody)
            {
                hitPart = hit.rigidbody.GetComponent <Part>();
                hitEva  = hit.rigidbody.GetComponent <KerbalEVA>();
                if (hitPart && allowPart && !hitEva & hitPart != partToAttach)
                {
                    isValidObj = true;
                }
                if (hitEva && allowEva)
                {
                    isValidObj = true;
                }
            }
            if (!hitPart && !hitEva && allowStatic)
            {
                isValidObj = true;
            }

            //Check distance
            bool isValidSourceDist = true;

            if (sourceTransform)
            {
                isValidSourceDist = Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, sourceTransform.position) <= maxDist;
            }
            bool isValidTargetDist = Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, hit.point) <= maxDist;

            //Set color
            if (!isValidObj)
            {
                color = Color.red;
            }
            else if (!isValidSourceDist || !isValidTargetDist)
            {
                color = Color.yellow;
            }
            color.a = 0.5f;
            foreach (MeshRenderer mr in allModelMr)
            {
                mr.material.color = color;
            }

            //Rotation keys
            Vector3 delta = new Vector3(0, 0, 1);

            if (Input.GetKey(KeyCode.LeftAlt))
            {
                delta = new Vector3(1, 0, 0);
            }
            else if (Input.GetKey(KeyCode.RightAlt))
            {
                delta = new Vector3(0, -1, 0);
            }

            if (Input.GetKeyDown(KASAddonControlKey.rotateLeftKey.ToLower()))
            {
                customRot -= delta * 15;
            }
            if (Input.GetKeyDown(KASAddonControlKey.rotateRightKey.ToLower()))
            {
                customRot += delta * 15;
            }

            Quaternion rotAdjust = Quaternion.Euler(0, 0, customRot.z) * Quaternion.Euler(customRot.x, customRot.y, 0);

            KAS_Shared.MoveAlign(pointer.transform, pointerNodeTransform, hit, rotAdjust);

            //Attach on click
            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                KAS_Shared.DebugLog("Attachment started...");
                if (!isValidObj)
                {
                    ScreenMessages.PostScreenMessage("Can't attach, target is not allowed !");
                    audioBipWrong.Play();
                    return;
                }

                if (!isValidSourceDist)
                {
                    ScreenMessages.PostScreenMessage("Can't attach, too far from source !");
                    audioBipWrong.Play();
                    return;
                }

                if (!isValidTargetDist)
                {
                    ScreenMessages.PostScreenMessage("Can't attach, too far from target !");
                    audioBipWrong.Play();
                    return;
                }

                KASModuleGrab modulegrab = partToAttach.GetComponent <KASModuleGrab>();


                //Move and attach mode
                if (pointerMode == PointerMode.MoveAndAttach)
                {
                    // Drop and detach part if needed
                    if (modulegrab)
                    {
                        if (modulegrab.grabbed)
                        {
                            modulegrab.Drop();
                        }
                        modulegrab.Detach();
                    }

                    KASModuleWinch connectedWinch = KAS_Shared.GetConnectedWinch(partToAttach);
                    if (!connectedWinch)
                    {
                        KAS_Shared.DecoupleFromAll(partToAttach);
                    }

                    //Move part
                    partToAttach.transform.position = pointer.transform.position;
                    partToAttach.transform.rotation = pointer.transform.rotation;

                    if (connectedWinch)
                    {
                        //Set cable lenght to real lenght
                        connectedWinch.cableJointLength = connectedWinch.cableRealLenght;
                    }

                    KAS_Shared.ResetCollisionEnhancer(partToAttach);

                    if (msgOnly)
                    {
                        KAS_Shared.DebugLog("UpdatePointer(Pointer) Attach using send message");
                        if (hitPart)
                        {
                            partToAttach.SendMessage("OnAttachPart", hitPart, SendMessageOptions.DontRequireReceiver);
                        }
                        else
                        {
                            partToAttach.SendMessage("OnAttachStatic", SendMessageOptions.DontRequireReceiver);
                        }
                    }
                    else
                    {
                        KAS_Shared.DebugLog("UpdatePointer(Pointer) Attach with couple or static method");
                        if (!hitPart && !hitEva)
                        {
                            if (modulegrab)
                            {
                                modulegrab.AttachStatic();
                                modulegrab.fxSndAttachStatic.audio.Play();
                            }
                            else
                            {
                                KAS_Shared.DebugWarning("UpdatePointer(Pointer) No grab module found, part cannot be attached on static");
                            }
                        }
                        else
                        {
                            partToAttach.Couple(hitPart);
                            if (modulegrab)
                            {
                                modulegrab.fxSndAttachPart.audio.Play();
                            }
                            else
                            {
                                KAS_Shared.DebugWarning("UpdatePointer(Pointer) No grab module found, cannot fire sound");
                            }
                        }
                        partToAttach.SendMessage("OnAttach", SendMessageOptions.DontRequireReceiver);
                    }
                }

                if (pointerMode == PointerMode.CopyAndAttach)
                {
                    // Not tested !
                    Part newPart = KAS_Shared.CreatePart(partToAttach.partInfo, pointer.transform.position, pointer.transform.rotation, partToAttach);
                    if (msgOnly)
                    {
                        if (hitPart)
                        {
                            StartCoroutine(WaitAndSendMsg(newPart, pointer.transform.position, pointer.transform.rotation, hitPart));
                        }
                        else
                        {
                            StartCoroutine(WaitAndSendMsg(newPart, pointer.transform.position, pointer.transform.rotation));
                        }
                    }
                    else
                    {
                        if (!hitPart && !hitEva)
                        {
                            StartCoroutine(WaitAndAttach(newPart, pointer.transform.position, pointer.transform.rotation, hitPart));
                        }
                        else
                        {
                            StartCoroutine(WaitAndAttach(newPart, pointer.transform.position, pointer.transform.rotation));
                        }
                    }
                }
                running = false;
            }
        }
Exemple #3
0
        public void Drop()
        {
            if (grabbed)
            {
                KAS_Shared.DebugLog("Drop - Dropping part :" + this.part.partInfo.name);
                base.SendMessage("OnPartDrop", SendMessageOptions.DontRequireReceiver);

                if (this.part.vessel.isEVA)
                {
                    this.part.decouple();
                }

                //Remove created joints between eva and part if exist
                KAS_Shared.RemoveFixedJointBetween(this.part, evaHolderPart);
                KAS_Shared.RemoveHingeJointBetween(this.part, evaHolderPart);

                List <Collider> allColliders = new List <Collider>(this.part.GetComponentsInChildren <Collider>() as Collider[]);
                foreach (Collider col in allColliders)
                {
                    col.isTrigger = false;
                }

                if (customGroundPos && evaHolderPart.checkLanded())
                {
                    KAS_Shared.MoveRelatedTo(this.part.transform, evaCollider.transform, dropPartPos, dropPartRot);
                }
                else
                {
                    KAS_Shared.MoveAlign(this.part.transform, partNode.nodeTransform, evaNodeTransform);
                }

                if (evaNodeTransform)
                {
                    Destroy(evaNodeTransform.gameObject);
                }
                if (evaJoint)
                {
                    Destroy(evaJoint);
                }

                this.part.transform.parent          = null;
                this.part.rigidbody.isKinematic     = false;
                this.part.physicalSignificance      = Part.PhysicalSignificance.FULL;
                this.part.rigidbody.velocity        = evaHolderPart.rigidbody.velocity;
                this.part.rigidbody.angularVelocity = evaHolderPart.rigidbody.angularVelocity;

                if (addPartMass & !physicJoint)
                {
                    evaHolderPart.mass = orgKerbalMass;
                }

                KASModuleWinch grabbedWinchHead = KAS_Shared.GetWinchModuleGrabbed(evaHolderPart.vessel);
                if (grabbedWinchHead)
                {
                    if (grabbedWinchHead.grabbedPortModule)
                    {
                        KAS_Shared.DebugLog("Drop - Grabbed part have a port connected");
                        grabbedWinchHead.PlugHead(grabbedWinchHead.grabbedPortModule, KASModuleWinch.PlugState.PlugDocked, fireSound: false);
                    }
                }

                evaJoint            = null;
                evaNodeTransform    = null;
                evaHolderVesselName = null;
                evaHolderPart       = null;
                grabbed             = false;

                RefreshContextMenu();

                //Send drop message to all child objects
                base.SendMessage("OnPartDropped", SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                KAS_Shared.DebugWarning("Drop - Part not grabbed, ignoring drop...");
            }
        }
Exemple #4
0
        public void Grab(Vessel kerbalEvaVessel)
        {
            KAS_Shared.DebugLog("Grab - Grabbing part :" + this.part.partInfo.name);

            //Get eva transform
            evaCollider = KAS_Shared.GetEvaCollider(kerbalEvaVessel, evaTransformName);
            if (!evaCollider)
            {
                KAS_Shared.DebugLog("Grab - " + evaTransformName + "transform not found on eva !");
                return;
            }

            //Get attach node
            if (attachNodeName == null || attachNodeName == "")
            {
                if (this.part.srfAttachNode == null)
                {
                    KAS_Shared.DebugLog("Grab - surface attach node cannot be found on the part !");
                    return;
                }
                KAS_Shared.AddNodeTransform(this.part, this.part.srfAttachNode);
                partNode = this.part.srfAttachNode;
            }
            else
            {
                AttachNode an = this.part.findAttachNode(attachNodeName);
                if (an == null)
                {
                    KAS_Shared.DebugLog("Grab - " + attachNodeName + " node cannot be found on the part !");
                    return;
                }
                KAS_Shared.AddNodeTransform(this.part, an);
                partNode = an;
            }

            //Send message to other modules
            base.SendMessage("OnPartGrab", kerbalEvaVessel, SendMessageOptions.DontRequireReceiver);

            //Drop grabbed part on eva if needed
            KASModuleGrab tmpGrabbbedPartModule = KAS_Shared.GetGrabbedPartModule(kerbalEvaVessel);

            if (tmpGrabbbedPartModule)
            {
                KAS_Shared.DebugWarning("Grab - Drop current grabbed part");
                tmpGrabbbedPartModule.Drop();
            }

            evaNodeTransform               = new GameObject("KASEvaNode").transform;
            evaNodeTransform.parent        = evaCollider.transform;
            evaNodeTransform.localPosition = evaPartPos;
            evaNodeTransform.rotation      = KAS_Shared.DirectionToQuaternion(evaCollider.transform, evaPartDir);

            KAS_Shared.MoveAlign(this.part.transform, partNode.nodeTransform, evaNodeTransform);

            //Grab winch connected head if any
            KASModuleWinch moduleWinch = KAS_Shared.GetConnectedWinch(this.part);

            if (moduleWinch)
            {
                KASModulePort modulePort = this.part.GetComponent <KASModulePort>();
                moduleWinch.UnplugHead(false);
                moduleWinch.GrabHead(kerbalEvaVessel, modulePort);
            }

            List <Collider> allColliders = new List <Collider>(this.part.GetComponentsInChildren <Collider>() as Collider[]);

            foreach (Collider col in allColliders)
            {
                col.isTrigger = true;
            }

            Detach();
            KAS_Shared.DecoupleFromAll(this.part);
            this.part.Couple(kerbalEvaVessel.rootPart);
            //Destroy joint to avoid buggy eva move
            Destroy(this.part.attachJoint);

            this.part.rigidbody.velocity = kerbalEvaVessel.rootPart.rigidbody.velocity;

            if (physicJoint)
            {
                if (evaJoint)
                {
                    Destroy(evaJoint);
                }
                evaJoint = this.part.gameObject.AddComponent <FixedJoint>();
                evaJoint.connectedBody = evaCollider.attachedRigidbody;
                evaJoint.breakForce    = 5;
                evaJoint.breakTorque   = 5;
            }
            else
            {
                this.part.physicalSignificance  = Part.PhysicalSignificance.NONE;
                this.part.transform.parent      = evaNodeTransform;
                this.part.rigidbody.isKinematic = true;
            }

            //Add grabbed part mass to eva
            if (addPartMass && !physicJoint)
            {
                orgKerbalMass = kerbalEvaVessel.rootPart.mass;
                kerbalEvaVessel.rootPart.mass += this.part.mass;
            }

            evaHolderVesselName = kerbalEvaVessel.vesselName;
            evaHolderPart       = kerbalEvaVessel.rootPart;
            grabbed             = true;

            RefreshContextMenu();

            //Play grab sound
            fxSndGrab.audio.Play();
            base.SendMessage("OnPartGrabbed", kerbalEvaVessel, SendMessageOptions.DontRequireReceiver);
        }
Exemple #5
0
        private bool AlignEvaPosition(Vessel kerbalEvaVessel)
        {
            //Get eva transform
            evaCollider = KAS_Shared.GetEvaCollider(kerbalEvaVessel, evaTransformName);
            if (!evaCollider)
            {
                KAS_Shared.DebugLog("Grab - " + evaTransformName + "transform not found on eva !");
                return(false);
            }

            //Get attach node
            if (attachNodeName == null || attachNodeName == "")
            {
                if (this.part.srfAttachNode == null)
                {
                    KAS_Shared.DebugLog("Grab - surface attach node cannot be found on the part !");
                    return(false);
                }
                KAS_Shared.AddNodeTransform(this.part, this.part.srfAttachNode);
                partNode = this.part.srfAttachNode;
            }
            else
            {
                AttachNode an = this.part.findAttachNode(attachNodeName);
                if (an == null)
                {
                    KAS_Shared.DebugLog("Grab - " + attachNodeName + " node cannot be found on the part !");
                    return(false);
                }
                KAS_Shared.AddNodeTransform(this.part, an);
                partNode = an;
            }

            //Send message to other modules
            base.SendMessage("OnPartGrab", kerbalEvaVessel, SendMessageOptions.DontRequireReceiver);

            //Drop grabbed part on eva if needed
            KASModuleGrab tmpGrabbbedPartModule = KAS_Shared.GetGrabbedPartModule(kerbalEvaVessel);

            if (tmpGrabbbedPartModule)
            {
                if (tmpGrabbbedPartModule.part.packed)
                {
                    KAS_Shared.DebugWarning("Grab - cannot drop an incompletely grabbed part!");
                    return(false);
                }

                KAS_Shared.DebugWarning("Grab - Drop current grabbed part");
                tmpGrabbbedPartModule.Drop();
            }

            if (evaNodeTransform)
            {
                Destroy(evaNodeTransform.gameObject);
            }

            evaNodeTransform               = new GameObject("KASEvaNode").transform;
            evaNodeTransform.parent        = evaCollider.transform;
            evaNodeTransform.localPosition = evaPartPos;
            evaNodeTransform.rotation      = KAS_Shared.DirectionToQuaternion(evaCollider.transform, evaPartDir);

            KAS_Shared.MoveAlign(this.part.transform, partNode.nodeTransform, evaNodeTransform);

            if (this.part.vessel == kerbalEvaVessel)
            {
                this.part.UpdateOrgPosAndRot(kerbalEvaVessel.rootPart);
            }

            return(true);
        }
Exemple #6
0
        public void ContextMenuStore()
        {
            KASModuleGrab moduleEvaGrab = KAS_Shared.GetGrabbedPartModule(FlightGlobals.ActiveVessel);

            if (!moduleEvaGrab || moduleEvaGrab.part.packed)
            {
                ScreenMessages.PostScreenMessage("You need to grab a part before", 2, ScreenMessageStyle.UPPER_CENTER);
                KAS_Shared.DebugWarning("ContextMenuStore - GetGrabbedPartModule return null !");
                return;
            }
            // Select the nearest compatible bay
            float      shorterDist    = Mathf.Infinity;
            AttachNode nearestBayNode = null;

            foreach (KeyValuePair <AttachNode, List <string> > bay in bays)
            {
                if (bay.Value != null)
                {
                    if (!bay.Value.Contains(moduleEvaGrab.bayType))
                    {
                        KAS_Shared.DebugWarning("ContextMenuStore - Part type : " + moduleEvaGrab.bayType + " is not allowed | Attach node : " + bay.Key.id);
                        foreach (string type in bay.Value)
                        {
                            KAS_Shared.DebugWarning("ContextMenuStore - Allowed type : " + type);
                        }
                        continue;
                    }
                }
                if (bay.Key.attachedPart)
                {
                    KAS_Shared.DebugWarning("ContextMenuStore - This node are used");
                    continue;
                }

                float distToBay = Vector3.Distance(FlightGlobals.ActiveVessel.transform.position, bay.Key.nodeTransform.position);
                if (distToBay <= shorterDist)
                {
                    shorterDist    = distToBay;
                    nearestBayNode = bay.Key;
                }
            }

            if (nearestBayNode == null)
            {
                ScreenMessages.PostScreenMessage("Part is not compatible or there is no free space", 2, ScreenMessageStyle.UPPER_CENTER);
                KAS_Shared.DebugWarning("ContextMenuStore - Part is not compatible or there is no free space");
                return;
            }

            AttachNode grabbedPartAn = moduleEvaGrab.part.findAttachNode(moduleEvaGrab.bayNode);

            if (grabbedPartAn == null)
            {
                KAS_Shared.DebugError("ContextMenuStore - Grabbed part bay node not found !");
                return;
            }

            KAS_Shared.DebugLog("ContextMenuStore - Drop part...");
            moduleEvaGrab.Drop();

            KAS_Shared.DebugLog("ContextMenuStore - Add node transform if not exist...");
            KAS_Shared.AddNodeTransform(moduleEvaGrab.part, grabbedPartAn);

            KAS_Shared.DebugLog("ContextMenuStore - Move part...");
            KAS_Shared.MoveAlign(moduleEvaGrab.part.transform, grabbedPartAn.nodeTransform, nearestBayNode.nodeTransform);
            moduleEvaGrab.part.transform.rotation *= Quaternion.Euler(moduleEvaGrab.bayRot);

            //Couple part with bay
            KAS_Shared.DebugLog("ContextMenuStore - Couple part with bay...");
            moduleEvaGrab.part.Couple(this.part);
            nearestBayNode.attachedPart = moduleEvaGrab.part;

            fxSndStore.audio.Play();
            moduleEvaGrab.part.SendMessage("OnBayStore", SendMessageOptions.DontRequireReceiver);
        }
Exemple #7
0
        public void Drop(bool forAttach = false)
        {
            if (grabbed)
            {
                KAS_Shared.DebugLog("Drop - Dropping part :" + this.part.partInfo.name);

                base.SendMessage("OnPartDrop", SendMessageOptions.DontRequireReceiver);

                if (this.part.vessel.isEVA || grab_pending)
                {
                    this.part.decouple();
                }

                if (grab_pending)
                {
                    Destroy(evaNodeTransform.gameObject);
                    evaNodeTransform    = null;
                    evaHolderVesselName = null;
                    evaHolderPart       = null;
                    grabbed             = grab_pending = false;
                    RefreshContextMenu();
                    return;
                }

                //Remove created joints between eva and part if exist
                KAS_Shared.RemoveFixedJointBetween(this.part, evaHolderPart);
                KAS_Shared.RemoveHingeJointBetween(this.part, evaHolderPart);

                List <Collider> allColliders = new List <Collider>(this.part.GetComponentsInChildren <Collider>() as Collider[]);
                foreach (Collider col in allColliders)
                {
                    col.isTrigger = (keepTriggers != null && keepTriggers.Contains(col));
                }

                if (customGroundPos && evaHolderPart.checkLanded())
                {
                    KAS_Shared.MoveRelatedTo(this.part.transform, evaCollider.transform, dropPartPos, dropPartRot);
                }
                else
                {
                    KAS_Shared.MoveAlign(this.part.transform, partNode.nodeTransform, evaNodeTransform);
                }

                if (evaNodeTransform)
                {
                    Destroy(evaNodeTransform.gameObject);
                }
                if (evaJoint)
                {
                    Destroy(evaJoint);
                }

                this.part.rigidbody.velocity        = evaHolderPart.rigidbody.velocity;
                this.part.rigidbody.angularVelocity = evaHolderPart.rigidbody.angularVelocity;

                KAS_Shared.ResetCollisionEnhancer(this.part);

                if (addPartMass & !physicJoint)
                {
                    evaHolderPart.mass = orgKerbalMass;
                }

                KASModuleWinch grabbedWinchHead = KAS_Shared.GetWinchModuleGrabbed(evaHolderPart.vessel);
                if (grabbedWinchHead)
                {
                    if (grabbedWinchHead.grabbedPortModule && grabbedWinchHead.grabbedPortModule.part == part)
                    {
                        KAS_Shared.DebugLog("Drop - Grabbed part have a port connected");

                        if (forAttach)
                        {
                            // Docked causes big problems when the part is later coupled
                            grabbedWinchHead.PlugHead(grabbedWinchHead.grabbedPortModule, KASModuleWinch.PlugState.PlugUndocked, fireSound: false);
                        }
                        else
                        {
                            grabbedWinchHead.PlugHead(grabbedWinchHead.grabbedPortModule, KASModuleWinch.PlugState.PlugDocked, fireSound: false);
                        }
                    }
                }

                GameEvents.onCrewBoardVessel.Remove(new EventData <GameEvents.FromToAction <Part, Part> > .OnEvent(this.OnCrewBoardVessel));

                syncGrab            = false;
                keepTriggers        = null;
                evaJoint            = null;
                evaNodeTransform    = null;
                evaHolderVesselName = null;
                evaHolderPart       = null;
                grabbed             = grab_pending = false;

                RefreshContextMenu();

                //Send drop message to all child objects
                base.SendMessage("OnPartDropped", SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                KAS_Shared.DebugWarning("Drop - Part not grabbed, ignoring drop...");
            }
        }
Exemple #8
0
        private IEnumerator GrabCoroutine(Vessel kerbalEvaVessel)
        {
            KAS_Shared.DebugLog("Grab - Grabbing part :" + this.part.partInfo.name);
            //Send message to other modules
            base.SendMessage("OnPartGrab", kerbalEvaVessel, SendMessageOptions.DontRequireReceiver);

            //Set attach node on EVA
            SetEvaNode(kerbalEvaVessel);

            //Drop grabbed eva part if any
            KASModuleGrab grabbbedPartModule = KAS_Shared.GetGrabbedPartModule(kerbalEvaVessel);

            if (grabbbedPartModule)
            {
                grabbbedPartModule.Drop();
            }

            //Unplug winch connected head if any
            KASModuleWinch moduleWinch = KAS_Shared.GetConnectedWinch(this.part);

            if (moduleWinch)
            {
                moduleWinch.UnplugHead(false);
            }

            //Disable all colliders on part
            DisableColliders();

            //Detach if needed
            Detach();

            //Decouple part (if not already done, in case of loading after a save with the part grabbed)
            if (this.part.vessel != kerbalEvaVessel)
            {
                KAS_Shared.DecoupleFromAll(this.part);
            }

            //Wait decouple action (x64 fix)
            yield return(new WaitForFixedUpdate());

            //Move part to eva node
            KAS_Shared.MoveAlign(this.part.transform, partNode.nodeTransform, evaNodeTransform);

            //Grab winch connected head if any
            if (moduleWinch)
            {
                KASModulePort modulePort = this.part.GetComponent <KASModulePort>();
                moduleWinch.GrabHead(kerbalEvaVessel, modulePort);
            }

            //Couple part to eva (if not already done, in case of loading after a save with the part grabbed)
            if (this.part.vessel != kerbalEvaVessel)
            {
                this.part.Couple(kerbalEvaVessel.rootPart);
            }

            //Destroy joint to avoid buggy eva move
            if (this.part.attachJoint)
            {
                this.part.attachJoint.DestroyJoint();
            }

            //Set part to physic join or kinematic with parent
            if (physicJoint)
            {
                if (evaJoint)
                {
                    Destroy(evaJoint);
                }
                evaJoint = this.part.gameObject.AddComponent <FixedJoint>();
                evaJoint.connectedBody = evaCollider.attachedRigidbody;
                evaJoint.breakForce    = 5;
                evaJoint.breakTorque   = 5;
                KAS_Shared.ResetCollisionEnhancer(this.part);
            }
            else
            {
                syncGrab = true;
                KAS_Shared.ResetCollisionEnhancer(this.part, false);
            }

            //Add grabbed part mass to eva
            if (addPartMass && !physicJoint)
            {
                orgKerbalMass = kerbalEvaVessel.rootPart.mass;
                kerbalEvaVessel.rootPart.mass += this.part.mass;
            }

            //Add event
            GameEvents.onCrewBoardVessel.Add(new EventData <GameEvents.FromToAction <Part, Part> > .OnEvent(this.OnCrewBoardVessel));

            //Set variables
            evaHolderVesselName = kerbalEvaVessel.vesselName;
            evaHolderPart       = kerbalEvaVessel.rootPart;
            grabbed             = true;
            grab_pending        = false;

            //Refresh Context Menu
            RefreshContextMenu();

            //Play grab sound
            fxSndGrab.audio.Play();

            //Send message to other modules
            base.SendMessage("OnPartGrabbed", kerbalEvaVessel, SendMessageOptions.DontRequireReceiver);
        }