// Update is called once per frame void Update() { if (screwed == false) { //Get rotation value float rot = countRotations.totalRotation; //Scale values //Truncate rot value if (rot > oldMax) { rot = oldMax; } if (rot < oldMin) { rot = oldMin; } //new_value = ( (old_value - old_min) / (old_max - old_min) ) * (new_max - new_min) + new_min" float val = ((rot - oldMin)) / (oldMax - oldMin) * (newMin - newMax) + newMax; screw.transform.localPosition = new Vector3(0f, val, 0f); //If we have finished screwing if (screw.transform.localPosition.y <= newMin) { screwed = true; PS.Spawn(Color.green, transform.position); } } else { screw.transform.localPosition = new Vector3(0f, newMin, 0f); } }
public void SnapFixedJoint(GameObject snapObj, GameObject snapEdge, bool isCorrectPart) { //Make child //Transform previousParent = transform.parent; //snapObj.transform.SetParent(transform); //snapObj.transform.GetComponent<VRTK.VRTK_InteractableObject>().setPreviousParent(transform); // ////Remove parent //snapObj.transform.parent = null; //snapObj.transform.GetComponent<VRTK.VRTK_InteractableObject>().setPreviousParent(null); //Make connected object FixedJoint fj = snapObj.AddComponent <FixedJoint>(); fj.connectedBody = GetComponent <Rigidbody>(); //Force one hand to stop interacting snapObj.GetComponent <VRTK.VRTK_InteractableObject>().ForceStopInteracting(); //check is correct part if (isCorrectPart) { spawnPS.Spawn(Color.green, snapEdge.transform.position); //Increment num parts PartCounter partCounter = transform.parent.GetComponent <PartCounter>(); if (partCounter != null) { partCounter.IncrementNumParts(); if (partCounter.IsComplete()) { spawnPS.Spawn(Color.green, partCounter.getMainPart().transform.position); } } } }