• 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 Fox-Handler · Sep 06, 2014 at 01:56 AM · quaterniondirection

Quaternion multiplication

I was studying this script from an example project and after comparing it to another tutorial, did some research on Quaternion multiplication. Now I am by no means a math whiz (only learning what I need to when necessary), But what I found interesting was this line right here

 direction.Normalize ();

I was reading this post http://answers.unity3d.com/questions/372371/multiply-quaternion-by-vector3-how-is-done.html and from what I could gather, Multiplying a quaternion by a vector3 or (Vector2) gives the same rotation. Because I thought the Horizontal and Vertical Input both have a magnitude of 1 anyways is using Vector3.normalize necessary?

 using UnityEngine;
 using System.Collections;
 
 /// <summary>
 /// Utilities to convert Joystiq input to worldspace ( based in main camera) 
 /// and to convert worldspace to Speed and Direction
 /// </summary>
 public class JoystickToWorld
 {    
     public static Vector3 ConvertJoystickToWorldSpace ()
     {        
             Vector3 direction;            
             float horizontal = Input.GetAxis ("Horizontal");
             float vertical = Input.GetAxis ("Vertical");        
             Vector3 stickDirection = new Vector3 (horizontal, 0, vertical);                                        
             direction = Camera.main.transform.rotation * stickDirection; // Converts joystick input in Worldspace coordinates //Quaterntion multiplication
             direction.y = 0; // Kill Z
             //direction.Normalize ();    <-------------
 
             return direction;
     }
 
     public static void ComputeSpeedDirection (Transform root, ref float speed, ref float direction)
     {
             Vector3 worldDirection = ConvertJoystickToWorldSpace ();
 
             speed = Mathf.Clamp (worldDirection.magnitude, 0, 1);
             if (speed > 0.01f) { // dead zone
                     Vector3 axis = Vector3.Cross (root.forward, worldDirection);
                     direction = Vector3.Angle (root.forward, worldDirection) / 180.0f * (axis.y < 0 ? -1 : 1);
             } else {
                     direction = 0.0f; 
             }
     }    
 } 

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
2
Best Answer

Answer by robertbu · Sep 06, 2014 at 02:18 AM

is using Vector3.normalize necessary?

Yes. Take a look at these three possible vectors from your code above: (1,0,0), (0,0,1), and (1,0,1). The magnitude of the first two is 1.0, but the magnitude of the last is sqrt(2). Without the Normalize(), your character would move faster when going in a diagonal direction. But you are right in thinking that the Quaternon multiplication does not change the magnitude of the vector.

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 Fox-Handler · Sep 06, 2014 at 02:50 AM 0
Share

right that makes sense. I got a little confused because in the other script the author doesn't normalize the direction Vector. He pretty much does the same thing except that. He does use vector3.sqrmagnitude for the speed though.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

22 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

Related Questions

Rotate object to target position 1 Answer

Get rotation from a vector direction. 1 Answer

How can I move an object to click point in 2D? 0 Answers

Rotate object based on hit normal + matching camera direction 0 Answers

[SOLVED] Receive a float from a quaternion? 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