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 /
avatar image
0
Question by TheBoski · Aug 18, 2016 at 02:21 PM · vector3valueanglesmodify

Calculate Vector3 based on the other Vector3

Hello fellow programmers!

So in my game I have two virtual joysticks each returning a Vector3 value representing the direction in which the joys are pushed.

One of the joysticks is located on the left , and the second one is on the right side of the screen. Let's call return values accordingly : Left Vector (LV) and Right Vector (RV).

My problem is that the Left Vector needs to be modified based on the input from the right joystick. What I mean is that angle between LV and RV needs to be maintained as it is, and the Right Vector should be treated like Vector3.up by the left joy.

I hope this quick sketch will make it easier to understand :

alt text

It is worth noting that the green arrow representing RV in the "HOW IT SHOULD BE" section is there only to show maintained angle between two Vectors. There is no need to physically change the direction of Right Vector.

I only need to get the changed direction of the Left Vector

It is a shot in the dark but maybe I can measure the angle between Right Vector and Vector3.up , then somehow add that angle to the Left Vector ? (I really don't know how it works in Unity)

Is there a function provided by Unity to do such tasks or I am completely wrong and I need a better approach?

Please help me with solving this issue. This is a part of my first kind of a serious project and without your help i may get stuck forever :(

Also, I'm sorry for any spelling mistakes I made since English is shamefully not my first language.

vector-problem.jpg (56.8 kB)
Comment
Add comment · Show 2
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 g__l · Aug 18, 2016 at 03:43 PM 0
Share

Nicely put together question, sadly i cannot assist you greatly but these links may send you in the right direction.

Finding the angle of a Vector - http://www.dummies.com/education/science/physics/how-to-find-the-angle-and-magnitude-of-a-vector/

Finding the angle between two Vectors - http://www.wikihow.com/Find-the-Angle-Between-Two-Vectors

@TheBoski

avatar image meat5000 ♦ · Aug 18, 2016 at 04:46 PM 0
Share

Dont rely on Vector3 and its shortcuts. Convert them to Vector2.

Without going in to it too much, here's a snippet of code from a Camera-Relative setup.

The angle of the camera (in y) is basically replaced by your Right Stick.

 #if UNITY_ANDROID
         //ANDROID JOYSTIC$$anonymous$$
         if(!Application.isEditor)
         {
             stickVector = Vector2(moveJoystick.position.x,moveJoystick.position.y);                
         }
     #endif
     
         var playerRotation : float = cameraCurrentT.rotation.eulerAngles.y - thisTransform.rotation.eulerAngles.y;
                 
         stickAngle = Vector2.Angle(Vector2(0,1),Vector2(stickVector.x,stickVector.y));
         var stickAngleCross : Vector3 = Vector3.Cross(Vector2(0.0,1.0), stickVector);
      
         if (stickAngleCross.z > 0.0)
         stickAngle = 360.0 - stickAngle;
         var inputRotQuat : Quaternion = Quaternion.AngleAxis((playerRotation),Vector3.up);
         
         var stickTemp : Vector3 = Vector3(stickVector.x,0.0,stickVector.y);
         modifierVector = inputRotQuat * stickTemp;
         
         modifiedInput.x = modifierVector.x;
         modifiedInput.y = modifierVector.z;

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Rotation from another object 1 Answer

Change a property based on angle? 1 Answer

Problem raycasting to quads at certain angles 0 Answers

LookAt formula in Vector3 1 Answer

More precise Vector3 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