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 WildHeart_Interactive · Aug 09, 2016 at 05:29 PM · c#rotationmovementvector3quaternion

Grabbing the Relative eulerAngles.y of a Rotation

I've run into a rather frustating problem today while doing some tests. I'm working on a physics based platformer, where movement is carried out by passing Vector3 to the player character and having them move towards the vector3 Via Rigidbody.AddForce. This is all well and good but this morning I'm trying to translate that system in to one where the player ignores normal gravity and has their gravity affected by a planetoid, this is where all of the problems start to crop up. Normally to find the Vector3 along which to move the player, I plug the input on the X and Y axis's into something like this:

     void GrabInput(){
         x = Input.GetAxis ("Horizontal");
         y = Input.GetAxis ("Vertical");
 
         direction =(relMoveRight * x) + (relMoveForward * y);
         target = direction + transform.position;
         crossHair.position = target;
     }
 
 void OrientAxis(){
         
         relMove = Quaternion.Euler(new Vector3(0f,mainCam.eulerAngles.y,0f));
         relMoveForward = relMove * Vector3.forward;
         relMoveRight = relMove * Vector3.right;
     }

And Here is the Code Dictating the cameras movement:

 void Update(){
         mainCam.rotation = Quaternion.Slerp (mainCam.rotation,CamRot(),smoothing*Time.deltaTime);
         mainCam.position = Vector3.Lerp (mainCam.position, CamPos(), smoothing * Time.deltaTime);
     }
 
 
     Quaternion CamRot(){
         Quaternion newRot = Quaternion.identity;
         newRot = Quaternion.Euler(camY,camX,0f);
         newRot = transform.rotation * newRot;
         return newRot;
     }
 
     Vector3 CamPos(){
         Vector3 newPos =  Vector3.zero;
 
         newPos = (CamRot () * new Vector3 (0f,0f,-zoom)+transform.position);
 
         return newPos;
     }

So as you can see, i make sure that the movement is relative to the Cameras Y rotation. The part i'm running into trouble with is to basically find the local equivalent of this line here:

     relMove = Quaternion.Euler(new Vector3(0f,mainCam.eulerAngles.y,0f));

I've messed around with various conversions such as transform.InverseTransformDirection and Quaternion.Inverse but have had no luck so far.

Any help would be greatly appreciated!

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 elenzil · Aug 09, 2016 at 07:24 PM

your OrientAxis() routine looks basically good to me, but you might want to negate the angle. ie, -1 * mainCam.eulerAngles.y .

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 WildHeart_Interactive · Aug 10, 2016 at 01:56 PM 0
Share

what do you mean by negate the angle?

avatar image elenzil WildHeart_Interactive · Aug 10, 2016 at 02:59 PM 0
Share

make it negative. ie, multiply by -1. thinking about it more, i'm not sure that's the right answer tho. i'm not sure i understand the scenario.

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 Perpendicular to Line Segment 1 Answer

Using quaternions to align game objects. 1 Answer

Rotate LOCAL y axis to match Joystick input 0 Answers

Help with raycast for for wall detection 1 Answer

Turn Based Movement - Using Movement Points 0 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