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 hypnoslave · Jan 23, 2012 at 02:38 AM · rotationmouse

spinning an object with mouse movement

Hey folks, I want to be able to swipe my mouse on the screen in a certain direction and have a floating on-screen cube rotate in a that direction, kind of in the same way it would look if the cube was static and the camera were to orbit around the cube - I want the cube to spin in the direction of mouse movement, basically.

for another example of what I'm trying to get at, think of what happens when you go to rotate an object in the editor with the rotation gizmo. click on the gizmo, but not on a specific axis -- between the axis, the object rotates in the direction of your mouse. that's the effect I want, but without the gizmo...

Anyone have any ideas?

Thanks!

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
1
Best Answer

Answer by Stardog · Jan 29, 2012 at 08:16 AM

I made this for picking up and rotating physics objects for an adventure game, but I've stripped it down. Mouse X/Y should be in Project Settings > Input by default.

 using UnityEngine;
 using System.Collections;
 
 public class ObjectRotate : MonoBehaviour {
     
     public float multiplier = 10f;
     
     void OnMouseDrag()
     {
         transform.Rotate(Input.GetAxis("Mouse Y") * multiplier, -Input.GetAxis("Mouse X") * multiplier, 0, Space.World);
     }
     
 }
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 hypnoslave · Jan 29, 2012 at 08:32 AM 0
Share

Thank you! that did it!

ugh, I'm an idiot. I had tried a similar thing at first, but I was using Input.GetAxis and I had made a stupid mistake setting up my axis in the input manager. I thought it was getting a bad result because of something regarding Quaternions or something.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to rotate an object around a fixed point so it follows the mouse cursor? 1 Answer

How to make an object rotate on the y axis towards the mouse? 3 Answers

Rotate object following mouse movement. Object jumps/ flips 1 Answer

Rotation of the mouse activates a boxcollider2d in javascript. 1 Answer

i want to rotate an object when i move my mouse over an UI image 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