Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by maxxa05 · Jun 03, 2012 at 10:59 PM · rotationcontrollerquaternion

Spaceship Rotation conversion

I'd like to calculate a rotation to be able to control a spaceship.

first of all, I would get the current rotation desired since last update.

 var presentRotation=Quaternion.identity
 presentRotation.eulerAngles=Vector3(x,y,z) (x,y,z being decided by the inputs)

then I would probably get the total desired rotation with the previous total rotation:

 rotation*=presentRotation

Now I would get the spaceship transform rotation and transfer it to quaternions. My problem comes after that, when I would like to get the rotation between the two rotation, get the euler angles of that rotation and then apply some torque according to the rotation needed. I can't see how I can obtain those angles. Is there a way to do that or is there a better way around?

Thanks

Comment
Add comment · Show 1
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 maxxa05 · Jun 03, 2012 at 11:14 PM 0
Share

I could probably only apply torque to my inputs and automatically applying torque against the angular speed, so it would kinda replicate angular drag. thing is, I want to stop my angular motion automatically so it's easier to pilot. I want to fake a automatic system so it doesn't look like I only put angular drag.

1 Reply

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

Answer by aldonaletto · Jun 03, 2012 at 11:56 PM

If you want to rotate the ship with your controls, the easiest way is to use Rotate:

  function Update(){
    var yaw = Input.GetAxis("Horizontal") * Time.deltaTime * 60; // yaw at 60 deg/sec
    var pitch = Input.GetAxis("Vertical) * Time.deltaTime * 45; // pitch at 45 deg/sec
    transform.Rotate(pitch, yaw, 0);
  }
But if you want to set the ship rotation to some specific XYZ angles, you can save the initial eulerAngles at Start, "rotate" this angles mathematically and assign them to transform.eulerAngles:

var angles: Vector3;

function Start(){ angles = transform.eulerAngles; }

function Update(){ var yaw = Input.GetAxis("Horizontal") Time.deltaTime 60; // yaw at 60 deg/sec var pitch = Input.GetAxis("Vertical) Time.deltaTime 45; // pitch at 45 deg/sec angles.y = (angles.y + yaw) % 360; angles.x = (angles.x + pitch) % 360; transform.eulerAngles = angles; } The last alternative is to have the axes assigned to different children:

 ShipYaw      // use this object to move and yaw    
   ShipPitch  // use this only to pitch

It's like above, but you should set ShipYaw.eulerAngles to (0, yaw, 0), and ShipPitch.localEulerAngles to (pitch, 0, 0).

Comment
Add comment · Show 2 · 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 maxxa05 · Jun 04, 2012 at 12:00 AM 0
Share

Thing is, I'd like to use AddTorque for my physic to be as realistic as possible

avatar image aldonaletto · Jun 04, 2012 at 01:07 AM 0
Share

You can apply torque ins$$anonymous$$d of setting the eulerAngles, like this:

function FixeedUpdate(){
  var yaw = Input.GetAxis("Horizontal") * 5;
  var pitch = Input.GetAxis("Vertical) * 5;
  rigidbody.AddTorque(pitch, yaw, 0);
}
But be aware that you will not have a reliable indication of the current angles about XYZ: the property transform.eulerAngles is actually the property transform.rotation converted to/from Euler angles, and may return weird (although correct) results at some sectors. Euler angles is a redundant system: there are several XYZ combinations that result in exactly the same actual rotation. When you read transform.eulerAngles, Unity convert the quaternion transform.rotation to one of these combinations, but at certain regions other different combinations may be returned - one angle may suddenly jump from near zero to -90, while other angles jump to other weird values.
If you want good physics simulation, apply the torque; if you need precise positioning, forget about torque and set the euler angles directly - unfortunately, you can't have both at the same time.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Transform a Vector by a Quaternion 1 Answer

Calculating Torque but cant add Quaternion 0 Answers

Lerp 180 degrees while holding B and lerp back 180 degrees when let go of B. 2 Answers

Joystick for WASD & Joystick for Camera? 0 Answers

player rotation to follow the mouse 2 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