private void KeepInHand(WandControlGeneralInteraction normWand) { // Set the position based on where the wand is posDelta = normWand.transform.position - interactionPoint.position; // Dont need this anymore because it breaks teleportation and is not necessary //if (posDelta.x > .75f || posDelta.y > .75f || posDelta.z > .75f) //{ // EndInteraction(normWand); //} this.ridge.velocity = posDelta * velocityFactor * Time.fixedDeltaTime; // Set the rotation based on where the wand is rotationDelta = normWand.transform.rotation * Quaternion.Inverse(interactionPoint.rotation); rotationDelta.ToAngleAxis(out angle, out axis); // Helps make it so it does not do a weird flip if (angle > 180) { angle -= 360; } // Check if any bad numbers come in try { if (float.IsNaN(axis.x) == false && float.IsNaN(axis.y) == false && float.IsNaN(axis.z) == false && float.IsNaN(this.ridge.angularVelocity.x) == false && float.IsNaN(this.ridge.angularVelocity.y) == false && float.IsNaN(this.ridge.angularVelocity.z) == false && float.IsNaN(rotationFactor) == false && float.IsNaN(angle) == false) { this.ridge.angularVelocity = (Time.fixedDeltaTime * angle * axis) * rotationFactor; //this.transform.rotation = normWand.transform.rotation; } } catch { Debug.Log("There was an error calculating the interactable objects velocity"); } }
public void EndInteraction(WandControlGeneralInteraction wand) { if (wand == attachedWand) // So the other wand cant trigger this { // Detach wand attachedWand = null; currentlyInteracting = false; } }
// At the start of an interaction public void StartInteraction(WandControlGeneralInteraction wand) { // Attach the wand attachedWand = wand; interactionPoint.position = wand.transform.position; interactionPoint.rotation = wand.transform.rotation; interactionPoint.SetParent(this.transform, true); currentlyInteracting = true; }