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 osrs320 · Jul 30, 2018 at 08:09 AM · rotationquaternionaxislookatinversetransformpoint

[Please!] Noob need's help with planet gravity movement.

So I have a capsule that uses custom gravity to walk around a sphere, I have used "camera.ScreenPointToRay" to get the point on the planet where I click and then "transform.movetowards" to have him move towards that point,

My problem is I need to have him look at the point he is moving towards but to ONLY ROTATE AROUND HIS LOCAL Y AXIS to look at it. This is confusing me as the capsule could be at any rotation given where he is located on the sphere.

I have added 2 gifs, this first one is how the player moves around the sphere. https://i.imgur.com/N9kqmUy.gifv

This second one shows how I want the capsule to look in the direction he is moving but I want him rotating ONLY AROUND Y AXIS. https://i.imgur.com/7UoAVhZ.gifv

Thankyou so much for your help! This has been giving me a headache for 3 days now!

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

2 Replies

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

Answer by osrs320 · Aug 03, 2018 at 05:59 AM

Figured out a way to do it, created a plane as a child on my capsule/player, flipped it upside down so that the first ray from screen to mouse goes through it, then I cast a second ray from the point on the ground in a transform.up direction which hits the plane at the same height at the player. I then look at that new vector for only one frame, and implement the step eno-Khaon suggested in the look at function. Everything works perfectly now I'm so happy lol XD

Comment
Add comment · 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
0

Answer by madks13 · Jul 30, 2018 at 08:38 AM

The simplest solution would be to use LookAt, then restore the x and z axis :

 var rotation = go.transform.rotation.eulerAngles;
 go.transform.LookAt(clickedPoint);
 go.transform.eulerAngles = new Vector3(rotation.x, go.transform.eulerAngles.y, rotation.z);

Or something like that. This is untested and unchecked but you get the idea.

Comment
Add comment · Show 4 · 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 Eno-Khaon · Jul 30, 2018 at 09:46 AM 0
Share

It looked like the general rotation was working and the clicked point is clearly defined, so it should be possible to simply enforce a new "up" for the second argument in Transform.LookAt(). In fact, if the local rotation is handled after movement for the current frame, you already have your new "up" available:

 // C#
 Vector3 currentUp = transform.up;
 transform.LookAt(clickedPoint, currentUp);
avatar image osrs320 Eno-Khaon · Jul 30, 2018 at 11:01 AM 0
Share

It's the closest i've gotten but still doesn't work, unfortunately as it says in the documentation for transform.LookAt "worldUp is only a hint vector. The up vector of the rotation will only match the worldUp vector if the forward direction is perpendicular to worldUp." :(

avatar image osrs320 osrs320 · Jul 30, 2018 at 11:13 AM 0
Share

If i could I could get the ".point" of my "RayCastHit" in "space.self" regardless of my rotation in world space that might work... but i'm not sure that's how "transform.InverseTransformPoint" works... i've messed around with it and i couldn't work it out.

Show more comments

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

122 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 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 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 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 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 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

Local child rotation and transform.LookAt 2 Answers

Finding the Euler angles of an object's rotation in terms of a different set of axes 0 Answers

Rotate with joystick - LookAt axis flipping 1 Answer

how can i substract one axis by 180? 2 Answers

Quaternion Equivalent of restricting an axes rotation to zero 3 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