• 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 Mike Miller · Jul 09, 2010 at 07:43 PM · rotationsphere

Rotate Point A on Sphere to Point B on Sphere

Imagine a globe (sphere). I have Point A (Miami FL) and Point B (Portland OR). I would like to rotate the globe so that:

  1. The position of the globe and main camera do not move
  2. Point A ends up where Point B was
  3. The globe rotates along the an axis that runs through the center of the sphere and is normal to the plane created by Point A, Point B, and the center of the sphere.

I have been using Quaternion.FromToRotation but I have not been able to come up with a good solution.

Any suggestions?

Thanks, Mike

Edit:

Vector3 pointA; Vector3 pointB; GameObject sphere;

//What should I put here?

sphere.transform.rotation = resultRotation

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

4 Replies

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

Answer by Case23 · Jul 09, 2010 at 07:49 PM

I hope i understand it right. If so i had a similar problem yesterday.

I used t$$anonymous$$s:

Quaternion rotation = Quaternion.LookRotation(targetVector);
Vector3 point = new Vector(x,y,z);
point = rotation  * point ;

Also instead of using a Vector you rotate it should work if you use the rotation on a transform.rotation of a GameObject.

Edit:

So i played around a little bit. I added one sphere in the middle of my scene, and two cubes.

// the cubes public GameObject pointA; public GameObject pointB; // the sphere public GameObject globe;

 Quaternion rotationA;
 Quaternion rotationB;

void Start() { // get the start rotation of the points rotationA = Quaternion.LookRotation(pointA.transform.position); rotationB = Quaternion.LookRotation(pointB.transform.position); }

void Update() { // here the sphere rotate from point a to b // to make the cubes follow the sphere, you have to calculat there position, // or put the gameobjects from the cbes inside the sphere globe.transform.rotation = Quaternion.Slerp(rotationA, rotationB, Time.time * 0.1f);
}

http://unity3d.com/support/documentation/ScriptReference/Quaternion.Slerp.html

was the function w$$anonymous$$ch helped me, it worked for me but im not sure if t$$anonymous$$s is the best way to do it

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 Mike Miller · Jul 09, 2010 at 08:06 PM 0
Share

I am not quite sure how to implement your suggestion. The output seems to be a point and I think I am looking for a rotation.

avatar image
1
Best Answer

Answer by cncguy · Jul 09, 2010 at 11:11 PM

I t$$anonymous$$nk you are on the right track with FromToRotation.

for the following to work your sphere would have to be at global (0,0,0)

Quaternion rot = Quaternion.FromToRotation (pointA, pointB);
sphere.transform.rotation *= rot; //Multiply rotations to get the resultant rotation.

if your sphere is not at global (0,0,0) you need to make sure that pointA and pointB relative to the sphere coord system and then use the following:

Quaternion rot = Quaternion.FromToRotation (pointA, pointB);
sphere.transform.localRotation *= rot; //Multiply rotations to get the resultant rotation.
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 Mike Miller · Jul 13, 2010 at 09:42 PM 0
Share

Thank you. This worked.

avatar image Mike Miller · Jul 13, 2010 at 09:52 PM 0
Share

I posted the full code I used below.

avatar image
0
Best Answer

Answer by Mike Miller · Jul 13, 2010 at 09:46 PM

cnc guy helped answer my question. T$$anonymous$$s is the code I ended up with. It allows a user to grab a point on a sphere and rotate the sphere from that point.

using UnityEngine; using System.Collections;

public class EarthTouchMovement : MonoBehaviour {

 bool hasGrabbedPoint = false;
 Vector3 grabbedPoint;

void Update () { if (Input.GetMouseButton(0)) {
if(!hasGrabbedPoint) { hasGrabbedPoint = true;
grabbedPoint = getTouchedPoint(); } else { Vector3 targetPoint = getTouchedPoint(); Quaternion rot = Quaternion.FromToRotation (grabbedPoint, targetPoint); transform.localRotation *= rot;
} } else hasGrabbedPoint = false;
}

Vector3 getTouchedPoint() { RaycastHit $$anonymous$$t; Physics.Raycast (Camera.main.ScreenPointToRay(Input.mousePosition), out $$anonymous$$t);

     return transform.InverseTransformPoint($$anonymous$$t.point);

} }

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 TotallyAtRandom · Oct 11, 2013 at 02:28 PM

Is there a simple way to modify t$$anonymous$$s solution to constrain the globe to stay right side up? Meaning, I want to keep the North Pole at the top instead of it ending up getting spun on its side. I guess it would spin on it's Y and X axis but not Z. Thanks.

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 Marsupilami · Oct 11, 2013 at 03:33 PM 0
Share

Try looking here..

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Rotating sphere with rigidbody attached 1 Answer

Sphere on cube floor doesn't rotate after too much delay 1 Answer

Sphere rotation based on object on the sphere 0 Answers

Friction issue with rotating sphere 1 Answer

How do i lock the position of the camera above the player relative to the origin point? 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