Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Tomdancer · Nov 07, 2016 at 02:17 PM · rotationquaternionangles

Need solution for rotation with player input of X, Y, Z

Hello,

I'm kind of stuck in my current project. So to give a proper explanation of the situation, I need to rotate a spaceship, in wich the player sits in, but here comes the hard part (at least for me), because this is going to be a vr game(GearVR), but will need a good amount of player input whitout any peripherals. I created a keypad, wich is able to take one, two, or three values, positive and negative numbers too. After inputting the required amount of values for the given function to work, it calls the function and that works with the input values from the keypad, in this case X, Y ,Z for rotation. So what i want to achieve is after the input, the player ship should smoothly rotate to face the given coordinates. This is my 3rd or 4th attempt at making it work, but I still keep getting really strange rotations. The problem is probably with my understanding of how Quaternions should work, I would like to get some help from anybody who can wrap his head around Quaternions and Angles and all that... Ideas of other solutions, even dumping the keypad mechanic are welcome also.

Sorry for the wall of text, and thanks for taking the time to read it ;)

This is the code i managed to get to work at least with false rotations. The relevant functions are the faceGivenCoordinates and rotateShip functions.

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class GyroStab : MainFrameApplication {
 
     public float rotationSpeed;
 
     Quaternion targetRotation;
     //Vector3 currentRotationAngle;
     Vector3 targetRotationAngle;
     public void stabilize()
     {
         mainFrameScreen.GetComponent<Text>().text = "GyroStab initiated...stabilizing ship.";
 
     }
     public void initialiseRotationalControls()
     {
         mainFrameScreen.GetComponent<Text>().text = "Initialising rotational controls,\nplease input the following parameters\nin this exact order:\nRotation X, Rotation Y, Rotation Z";
         keypad.GetComponent<KeyPadScript>().activatingFunction = KeyPadScript.function.GyroStab;
         keypad.GetComponent<KeyPadScript>().activatingButtonGameObject = this.gameObject;
         //keypad "felnyit�sa" haszn�lathoz
     }
     public void faceGivenCoordinates(int rotationX, int rotationY, int rotationZ)
     {
         mainFrameScreen.GetComponent<Text>().text += "Starting rotation towards given coordinate: [ " + rotationX + ", " + rotationY + ", " + rotationZ + " ]";
 
         //cockpit �s ship model aktu�lis forgat�sa
         //currentRotationAngle = spaceCraft.transform.eulerAngles;
         targetRotationAngle = new Vector3(rotationX, rotationY, rotationZ);
 
         targetRotation = Quaternion.LookRotation(targetRotationAngle);
         StartCoroutine(rotateShip());
     }
     IEnumerator rotateShip()
     {
         rotationSpeed = 0.25f;
         Quaternion startingRotation = spaceCraft.transform.rotation;
 
         Debug.Log(startingRotation);
         Debug.Log(targetRotation);
 
         for (float i = 0f; i < 1f; i += rotationSpeed * Time.deltaTime)
         {
             spaceCraft.transform.rotation = Quaternion.Lerp(startingRotation, targetRotation, i);
             yield return null;
 
             Debug.Log("tick");
         }
 
         spaceCraft.transform.rotation = targetRotation;
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by X10KND · Nov 21, 2016 at 04:07 PM

Ah I got lost in the script (viewing this in mobile)

Try this (sorry if it is hard to read cuz I'm typing from a mobile device)

This script will be attached to the spaceship

Vector3 target;

void Update () {

 target = new Vector3 (put x value here, put y value here, put z value here);

 transform.LookAt(target);

}

If it is not smooth, notify me.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Tomdancer · Dec 06, 2016 at 11:06 AM 0
Share

Thanks for the answer! This was a posted a long time ago, I've already solved the problem by reworking the way rotations will be done, but thank you for you :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

89 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I find direction with known 2 projection angles on xz and yz planes? 2 Answers

Copy Roll From one Gameobject to another Without other rotations effecting it 0 Answers

Rotation Lerp Question 2 Answers

How to add to a rotation angle? 0 Answers

Determining if my target is standing upright 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges