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 sascham · Dec 10, 2011 at 01:17 PM · mouserotate

Rotate Object with with mouse

Hi

I found the script below here in the forum. It works great but it turns the object around itself, means, once it's back is front, moving the mouse up becomes down and the other way around. I would need to modify it to use Space.World but can not figure it out.

 var speed : int;

var friction : float;

var lerpSpeed : float;

private var xDeg : float;

private var yDeg : float;

private var fromRotation : Quaternion;

private var toRotation : Quaternion;

function Update () { if(Input.GetMouseButton(0)) {

     xDeg -= Input.GetAxis("Mouse X") * speed * friction;

     yDeg += Input.GetAxis("Mouse Y") * speed * friction;

     fromRotation = transform.rotation;

     toRotation = Quaternion.Euler(yDeg,xDeg,0);

     transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime  * lerpSpeed);

 }

}

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 asafsitner · Dec 11, 2011 at 12:18 AM 0
Share

Is this for a first-person view, or a top-down look-at-mouse-position, or just move-mouse-rotate-object thing?

avatar image sascham · Dec 11, 2011 at 04:13 AM 0
Share

just a move-mouse-rotate-object thing, a fixed object with a fixed camera

avatar image sascham · Dec 11, 2011 at 04:13 AM 0
Share

it's a mouse rotate object thing, te object is fixed and the camera is fixed, i just want to turn the object

avatar image Bunny83 · Dec 11, 2011 at 04:16 AM 0
Share

@sascham: Don't use the answer function unless you want to answer your own question. Use the "add new comment" button below the post you want to comment. If you want to clarify / add things to your question you can edit any of your posts.

I've converted your answers to comments

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by asafsitner · Dec 12, 2011 at 09:20 AM

Try using transform.Rotate instead. Something like this should work (c#, but the principle is the same):

 using UnityEngine;
 
 public class Rotate : MonoBehaviour
 {
     public float RotationSpeed = 5;
     
     // Update is called once per frame
     void Update () 
     {
         transform.Rotate((Input.GetAxis("Mouse X") * RotationSpeed * Time.deltaTime), (Input.GetAxis("Mouse Y") * RotationSpeed * Time.deltaTime), 0, Space.World);
     }
 }


I'd suggest switching the X and Y axes to make the rotation more intuitive (i.e. dragging the mouse left-right to rotate the object left-right instead of up-down) but that depends on your intention of course.

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

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

Can't get "rotate to mouse" script to work? 0 Answers

Look around when holding down mousebutton 1 Answer

Camera rotate with mouse in TPC 0 Answers

How do I rotate an object with the mouse? 1 Answer

rotate object to face mouse cursor x/z top down shooter 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