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 jotahd26 · Aug 29, 2019 at 03:00 PM · rotationclock

Problem with rotating an object

Hi there, I have a problem with my game, I am trying to make an analog 3D clock, I am supposed to rotate a handle that usually sets the time, doing it with the mouse, but when I do that the rotation does not happen as expected, at least I do not know how to do it right, it does not rotate more than 360º, can make a full turn but back when it reaches 360º.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 public class rotate : MonoBehaviour
 {
     public float angle;
     public Transform minutehand;
     public Transform hourshand;
     private Quaternion offset;
     public float rotateregulator;
     void Start()
     {
     }
     void Update()
     {
         minutehand.transform.localRotation = Quaternion.Euler(new Vector3(0, rotateregulator*2, 0));
 
         
     }
     void OnMouseDrag()
     {
         float x = Input.GetAxis("Mouse X");
         transform.RotateAround(transform.position, new Vector3(0, 0, 1) * Time.deltaTime*x, angle);
         rotateregulator = transform.rotation.eulerAngles.x;
     }
 }

Below you can see an animation of what is happening:

https://drive.google.com/open?id=1dCtjMI7vLAiX72ZoSuaUhEvVuLqrv7xo

What do i need to do to make it right?

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
0

Answer by I_Am_Err00r · Aug 29, 2019 at 04:06 PM

I'm not going to lie, I'm not sure this will fix your problem, but I'd like to suggest an if statement inside of that OnMouseDrag that might do something like this:

 void OnMouseDrag()
 {
     float x = Input.GetAxis("Mouse X");
     transform.RotateAround(transform.position, new Vector3(0, 0, 1) * Time.deltaTime*x, angle);
     rotateregulator = transform.rotation.eulerAngles.x;
     if(rotateregulator > 360)
     {
         rotateregulator = 0;
     }
 }

I don't have access to Unity right now and have never tried something like this myself, so I don't know how that would look and if it's not a good solution, my apologies.


I'll have access to Unity about an hour and I might have something more solid if that doesn't fix it, let me know please.

Comment
Add comment · Show 8 · 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 jotahd26 · Aug 29, 2019 at 05:44 PM 0
Share

Nice try, but it seems to stay the same I change this line:

 $$anonymous$$utehand.transform.localRotation = Quaternion.Euler(new Vector3(0, rotateregulator, 0));

Now it do this: https://drive.google.com/open?id=1NpONIlIAE8e58QfnGk$$anonymous$$crQBgylXFULkz Starts at Y=90º and goes to Y=-90º and then goes back again

avatar image I_Am_Err00r jotahd26 · Aug 29, 2019 at 07:52 PM 0
Share

$$anonymous$$y bad, I completely forgot about this during lunch, but I left something out last time, try this:

  if(rotateregulator > 360)
      {
          rotateregulator = 0;
          transform.rotation.eulerAngles = new Vector3(0,0,1);
      }

Let me know if that is any better for you, if it doesn't work I'll be able to try with Unity in about a couple hours and get back with you.

avatar image jotahd26 I_Am_Err00r · Aug 29, 2019 at 10:48 PM 0
Share

There seems to be an error when I added the line of code:´

alt text

ewwef.png (41.8 kB)
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

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

Clock script not working 1 Answer

Rotation changes direction for no reason? 0 Answers

Programming Accurate Clock Hands 1 Answer

Flip over an object (smooth transition) 3 Answers

Circular Rotation Input 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