Quantcast
Channel: Questions in topic: "rotating"
Viewing all articles
Browse latest Browse all 173

Rotate GameObject on specific axis

$
0
0
Hello together I'm a Unity beginner, so my question is may easy to answer to you. But I'm struggling now for a while and don't know what to do else. I want to implement a "Holographic Puzzle" for the Windows HoloLens. For that I want to rotate my puzzle Parts. Simplified my puzzle parts are just cubes. The user target these puzzle parts with "Gaze", a ray coming out of the users head in the direction the user is looking. If the ray hits an object (puzzle part), I draw an indicator to show that the user can rotate this object. This Indicator is on transformed to the plane which is hit. See Image below. For that I transform the indicator: // Assign gameObject's transform up vector equals GazeManager's instance Normal. gameObject.transform.up = GazeManager.Instance.Normal; ![Indicator][1] Now my problem: I want to rotate the GameObject if the user make a Gesture. This rotation should be around this GazeManager's instance Normal AND the rotation should be arround the center of the GameObject. See Image below. ![alt text][2] I tried a lot and searched a lot, but nothing worked. I paste my actual code below. If someone can help me it would be very friendly Thanks a lot, Lukas Code: public class GestureAction : MonoBehaviour { .... private Vector3 startUpdateNormalPosition = Vector3.zero; private Vector3 startUpdateGazeOriginPosition = Vector3.zero; .... void PerformNavigationStart(Vector3 position) { Debug.Log("PerformNavigationStart"); startUpdateNormalPosition = GazeManager.Instance.Normal; startUpdateGazeOriginPosition = GazeManager.Instance.gazeOrigin; } void PerformNavigationUpdate(Vector3 position) { // Debug.Log("PerformManipulationUpdate"); // rotationFactor = GestureManager.Instance.NavigationPosition.z * RotationSensitivity; Vector3 navigationDirection = AppContext.Instance.AppState.NavigationStartPosition - position; float rotationMaximum = Mathf.Max(navigationDirection.x, navigationDirection.y, navigationDirection.z); Debug.Log("rotationMaximum: " + rotationMaximum); // Apply rotation to object //transform.Rotate(new Vector3(rotationFactor_X, -1 * rotationFactor_Y, rotationFactor_Z)); // transform.Rotate(new Vector3(0, -1 * rotationFactor, 0)); // transform.Rotate(rotationVector, rotationSpeed); // Vector3 worldRotation = this.transform.TransformDirection(AppContext.Instance.AppState.NavigationStartRotationAxis); Vector3 worldRotation = this.transform.TransformDirection(AppContext.Instance.AppState.NavigationStartRotationAxis); // transform.Rotate(worldRotation, rotationSpeed); transform.RotateAround(startUpdateGazeOriginPosition, startUpdateNormalPosition, rotationMaximum*20*Time.time); } } [1]: /storage/temp/81508-indicator.png [2]: /storage/temp/81509-capture.png

Viewing all articles
Browse latest Browse all 173

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>