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 Kakalop · Aug 06, 2014 at 08:27 PM · rotationjavascriptmovement

Erratic behaviour during rotation

After a one-week battle of reading the other topics on the forum and numerous tries to alter my code I need your help with defining a proper rotation logic. My problem is that, at a certain angle, the objects forget that they should rotate and stop in place until the player moves near them at a specific angle, as can be seen in the video. http://www.megafileupload.com/en/file/556113/Rotation-Flip-wmv.html

I know the answer is probably painfully obvious, but I just can't understand how to do it and I'm just too short a unityscript coder to grasp the Quaternion and eulerAngles, so if you could at least pinpoint in which direction I should go to understand this. I don't want to copy others script because it will put me nowhere in the long run.

Here is the code which I am currently trying to work:


var rotation = Quaternion.LookRotation(astTarget.position - astSelf.position);
astSelf.rotation = Quaternion.Slerp (astSelf.rotation, rotation, astSmoTur * Time.deltaTime);
astSelf.rotation.y = 0;
astSelf.rotation.x = 0;
And here is the additional code attached to the object:

function Update()     
var newSpeed = asteroidSpeed * Time.deltaTime; 
transform.position = Vector3.MoveTowards (transform.position, asteroidTarget.position, newSpeed);    
transform.Translate (Vector3.right * newSpeed); 

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

Answer by rutter · Aug 06, 2014 at 09:16 PM

This bit:

 astSelf.rotation.y = 0;
 astSelf.rotation.x = 0;

Most designers are used to working with "Euler angles", which is what you'll see in the inspector, but Unity's internals use quaternions to represent rotation. They're quite a bit more complicated, but do have some advantages I won't go into. You almost never want to edit a quaternion manually.

From the manual:

They are based on complex numbers and are not easy to understand intuitively. You almost never access or modify individual Quaternion components (x,y,z,w)

You can convert back and forth easily, though:

 var euler = astSelf.eulerAngles;
 euler.x = 0;
 euler.y = 0;
 astSelf = Quaternion.Euler(euler);
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 Kakalop · Aug 07, 2014 at 07:35 PM 0
Share

I have made an attempt to convert the previously provided code with quaternions into eulerAngles, but although the objects will no longer get themselves locked, their local (?) rotation alongside the Z axis will not take place at all - the objects will simply move towards the player alongside the x and y axes without turning around.

I guess it is too difficult for me, at least at this point, to figure out this concept. I just can't visualize this in my head and the Unity 3D manual doesn't help that much.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Problem changing 3rd Person controller rotation 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Locking move direction and rotation in JavaScript 1 Answer


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