Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 khoatic · Dec 15, 2013 at 11:57 AM · rotate objectmouselookmove an objectrotatearound

Object Rotating around center from Mouse Movement

Im trying to have the mouse cursor control an object the player holds so that the object rotates around the player. To give a better picture of what I am looking for, the player is the earth and the object is the moon. I want to have the mouse to move around and determine which way the moon rotates. keep in mind this is a 3rd person 3d game. Any help would be greatly appreciated.

Comment
Add comment · Show 4
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 robertbu · Dec 15, 2013 at 03:31 PM 0
Share

2D or 3D? Do you want the mouse to control the angle are is it only controlling the direction, or do you just want horizontal movement of the mouse to spin the moon around the planet? What code (if any) are you using for making the planet orbit now?

avatar image khoatic · Dec 15, 2013 at 09:14 PM 0
Share

this is 3D, I want to mouse to move around the player and the moon follow the mouse. I provided a picture to more precisely explain what im wanting. I have some code im working with, if possible Id like to avoid the raycast check of where the mouse colliders with the ground because i have multiple objects in the scene as well, but if not its not really an issue. This is what i have:

 Ray rayTo$$anonymous$$ouse =Camera.main.ScreenPointToRay(Input.mousePosition); 
 RaycastHit hit;
 if(Physics.Raycast(rayTo$$anonymous$$ouse, out hit)) 
 {
 if(hit.collider.tag == "Ground"){
 float ang = $$anonymous$$athf.Atan2(hit.point.x-lookAtObj.transform.position.x,hit.point.x-lookAtObj.transform.position.x);
             lookAtObj.transform.RotateAround(this.transform.position,Vector3.up,ang);
             this.transform.LookAt(lookAtObj.transform.position);
 }
 }

alt text

untitled-1.png (14.6 kB)
avatar image murkertrer · Apr 24, 2014 at 03:17 PM 0
Share

Hi $$anonymous$$hoatic, Im trying to do the same now, I see that you did not get a satisfying answer.

Have you comed up with a solution yet?

regards

avatar image robertbu · Apr 24, 2014 at 03:49 PM 0
Share

@murkertrer - I did not answer this question the one time I read it because it did not contain enough information. Even now with the additional information I still have questions. Here is a bit of code to get you started. It positions the object in orbit, but it does not change the object orientation. It expects a camera rotation of (0,0,0). You need initialize the 'center' variable through drag and drop.

 #pragma strict
  
 var center : Transform;
 private var dist : float;
 
 function Start() {
     dist = (transform.position - center.position).magnitude;
 }
  
 function Update () {
     var pos = Input.mousePosition;
     pos.z = transform.position.z - Camera.main.transform.position.z;
     pos = Camera.main.ScreenToWorldPoint(pos);
     transform.position = (pos - center.position).normalized * dist;
 }

If this is not what you want (and @khoatic doesn't give you what you want), I recommend opening a new question. Be very specific in your new question.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AW0610AUT · Dec 15, 2013 at 12:45 PM

I´m not really sure what you want but if you need the moon itself to rotate you can just use the Spin script that is already in unity.

 var rotSpeed: float = 60; // degrees per second
  
 function Update(){
   transform.Rotate(0, rotSpeed * Time.deltaTime, 0, Space.World);
 }

If you want the moon to follow the mouse aswell you can make it a child of your camera.

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 khoatic · Dec 15, 2013 at 09:16 PM 0
Share

Please look at the comment above. Im wanting the Spin to follow the mouse. Im not looking for a simple spin that rotates with time 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.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

How this move my gear to the right and to the top with one click without falling 0 Answers

Rotate a vector around a certain point. 3 Answers

Quaternion reset rotations didnt smooth 0 Answers

How Do I add rotations to one of my objects in my AR application? 1 Answer

How can I pause the first person character camera rotation in this case?? 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