{"action":"created","issue":{"url":"https://api.github.com/repos/Angel-125/KerbalActuators/issues/2","repository_url":"https://api.github.com/repos/Angel-125/KerbalActuators","labels_url":"https://api.github.com/repos/Angel-125/KerbalActuators/issues/2/labels{/name}","comments_url":"https://api.github.com/repos/Angel-125/KerbalActuators/issues/2/comments","events_url":"https://api.github.com/repos/Angel-125/KerbalActuators/issues/2/events","html_url":"https://github.com/Angel-125/KerbalActuators/issues/2","id":305633575,"number":2,"title":"magnet code","user":{"login":"flagmaggot","id":16430694,"avatar_url":"https://avatars1.githubusercontent.com/u/16430694?v=4","gravatar_id":"","url":"https://api.github.com/users/flagmaggot","html_url":"https://github.com/flagmaggot","followers_url":"https://api.github.com/users/flagmaggot/followers","following_url":"https://api.github.com/users/flagmaggot/following{/other_user}","gists_url":"https://api.github.com/users/flagmaggot/gists{/gist_id}","starred_url":"https://api.github.com/users/flagmaggot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flagmaggot/subscriptions","organizations_url":"https://api.github.com/users/flagmaggot/orgs","repos_url":"https://api.github.com/users/flagmaggot/repos","events_url":"https://api.github.com/users/flagmaggot/events{/privacy}","received_events_url":"https://api.github.com/users/flagmaggot/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-03-15T16:47:11Z","updated_at":"2018-03-16T17:11:16Z","closed_at":null,"author_association":"NONE","body":"        GameObject _hook;\r\n        GameObject _target;\r\n        Rigidbody _rb;\r\n        Rigidbody _targetRb;\r\n        ConfigurableJoint _joint;\r\n\t\t\r\n[KSPEvent(guiActive = true, guiName = \"Magnet: Off\", active = true, guiActiveUnfocused = true, unfocusedRange = 40f)]\r\n        public void MagnetToggle()\r\n        {\r\n            if (_target != null && connected == false)\r\n            {\r\n                //_joint = new ConfigurableJoint();\r\n                _rb = _hook.AddComponent<Rigidbody>();\r\n                _rb.isKinematic = true;\r\n                //_rb.mass = 0.1f;\r\n                //_rb.useGravity = false;\r\n                //_rb.constraints = RigidbodyConstraints.FreezeAll;\r\n\r\n                _joint = _hook.AddComponent<ConfigurableJoint>();\r\n\r\n                _joint.xMotion = ConfigurableJointMotion.Locked;\r\n                _joint.yMotion = ConfigurableJointMotion.Locked;\r\n                _joint.zMotion = ConfigurableJointMotion.Locked;\r\n\r\n                _joint.angularXMotion = ConfigurableJointMotion.Locked;\r\n                _joint.angularYMotion = ConfigurableJointMotion.Locked;\r\n                _joint.angularZMotion = ConfigurableJointMotion.Locked;\r\n\r\n                _joint.connectedBody = _targetRb;\r\n                connected = true;\r\n                Events[\"MagnetToggle\"].guiName = \"Magnet: On\";\r\n\r\n            }\r\n            else if (connected == true)\r\n            {\r\n                UnityEngine.Object.Destroy(_joint.GetComponent<ConfigurableJoint>());\r\n                UnityEngine.Object.Destroy(_rb.GetComponent<Rigidbody>());\r\n                connected = false;\r\n                Events[\"MagnetToggle\"].guiName = \"Magnet: Off\";\r\n            }\r\n        }\r\n\t\t\r\n\t\tpublic override void OnStart(PartModule.StartState state)\r\n        {\r\n            base.OnStart(state);\r\n            if (HighLogic.LoadedSceneIsFlight)\r\n            {\r\n                //Debug.LogError(hookObjectName);\r\n                //_hook = transform.Search(hookObjectName).gameObject;\r\n                _hook = part.FindModelTransform(attachNode).gameObject;\r\n                isReady = true;\r\n\r\n            }\r\n\r\n        }\r\n\t\t\r\n\t\t\r\n\t\t[KSPField(guiName = \"Ray\", guiActive = true)]\r\n        public string ravInfo;\r\n\r\n        //private Rigidbody hitBody = null; //current hit reference\r\n        //bool connectable;\r\n        bool connected;\r\n        //Part hitPart;\r\n        private ConfigurableJoint joint_rotate;\r\n        //DockedVesselInfo vesselRef;\r\n        Part ref_hitPart;\r\n        //String partRef;\r\n\r\n        RaycastHit hit;\r\n        public Vector3 cameraPosition; //{ get { return armTip.position + armTip.up.normalized * 0.4f; } }\r\n        public Vector3 cameraForward; //{ get { return armTip.up; } }\r\n        //public Vector3 cameraNormal; //{ get { return armTip.forward; } }\r\n        void FixedUpdate()\r\n        {\r\n\r\n            if (drawAttachRay && HighLogic.LoadedSceneIsFlight)\r\n            {\r\n                //DebugDrawer.DebugLine(cameraPosition, cameraPosition + cameraForward * attachRange, Color.red);\r\n                //DrawLine\r\n                \r\n            }\r\n\r\n            cameraPosition = part.FindModelTransform(attachNode).position;\r\n            cameraForward = part.FindModelTransform(attachNode).forward;\r\n            RaycastHit hit;\r\n            int tempLayerMask = ~layerMask;\r\n            if (!connected && Physics.Raycast(cameraPosition, cameraForward, out hit, attachRange, tempLayerMask))\r\n            {\r\n                ravInfo = hit.collider.gameObject.name.ToString();\r\n                try\r\n                {\r\n                    _target = hit.collider.gameObject;\r\n                    _targetRb = (hit.rigidbody);\r\n                }\r\n                catch (NullReferenceException) { }\r\n            }\r\n            else\r\n            {\r\n                ravInfo = \"\";\r\n                _target = null;\r\n            }\r\n        }\r\n\t\t\r\n\t\t\r\n---PART CONFIG \r\nMODULE\r\n{\r\n name = WhateverYouHaveYourModuleAs\r\n attachNode = MagnetTrigger  //<------name of the mesh you want to use as a raycast\r\n attachRange = 0.5\r\n drawAttachRay = true\r\n}"},"comment":{"url":"https://api.github.com/repos/Angel-125/KerbalActuators/issues/comments/373782000","html_url":"https://github.com/Angel-125/KerbalActuators/issues/2#issuecomment-373782000","issue_url":"https://api.github.com/repos/Angel-125/KerbalActuators/issues/2","id":373782000,"user":{"login":"flagmaggot","id":16430694,"avatar_url":"https://avatars1.githubusercontent.com/u/16430694?v=4","gravatar_id":"","url":"https://api.github.com/users/flagmaggot","html_url":"https://github.com/flagmaggot","followers_url":"https://api.github.com/users/flagmaggot/followers","following_url":"https://api.github.com/users/flagmaggot/following{/other_user}","gists_url":"https://api.github.com/users/flagmaggot/gists{/gist_id}","starred_url":"https://api.github.com/users/flagmaggot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flagmaggot/subscriptions","organizations_url":"https://api.github.com/users/flagmaggot/orgs","repos_url":"https://api.github.com/users/flagmaggot/repos","events_url":"https://api.github.com/users/flagmaggot/events{/privacy}","received_events_url":"https://api.github.com/users/flagmaggot/received_events","type":"User","site_admin":false},"created_at":"2018-03-16T17:11:16Z","updated_at":"2018-03-16T17:11:16Z","author_association":"NONE","body":"In your CFG for the \"Rotator Hand\" portion I have this:\r\n\r\nMODULE\r\n\t{\r\n\t\t//This module handles mesh rotation operations such as an engine nacelle pivot.\r\n\t\tname = WBIRotationController\r\n\r\n\t\t//(Optional, defaults to Actuator) User-friendly name of the rotation controller.\r\n\t\trotatorName = Rotate Hand\r\n\r\n\t\t//(Optional, defaults to Engine) Group ID for the actuator. Allows you to differentiate\r\n\t\t//between the VTOL manager (which uses the Engine group), and, say, a robot arm manager.\r\n\t\tgroupID = Arm\r\n\r\n\t\t//Name of the pivot z+ points down the length of the arm. See Unity model.\r\n\t\trotationMeshName = Hand\r\n\r\n\t\t//Rotation axis of the pivot (x, y, z)\r\n\t\trotationMeshAxis = 0,0,1\r\n\r\n\t\t//We'll use the Servo Manager to control the rotation\r\n\t\t//(defaults to true, so we have the buttons in the right-click menu)\r\n\t\tguiVisible = false\r\n\r\n\t\t//We don't do symmetry with this part. This is used for engines for the most part.\r\n\t\tcanMirrorRotation = false\r\n\r\n\t\t//How fast to rotate the pivot\r\n\t\trotationDegPerSec = 15\r\n\t\t//magnetTransformName = MagnetTrigger\r\n\t\tmagnetTransformName = magnetTransform\r\n\t\t\r\n\t}"}}
{"actor":{"display_login":"flagmaggot"}}