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 Ekta-Mehta-D · Apr 11, 2015 at 05:36 AM · rotationjavascript360-degrees

Calculate one lap completion Unity3d

Hii all..

I am having one circle sprite with circle collider. I am continuous rotating this circle on z axis by using :

 transform.Rotate( 0  , 0 , speed * Time.DeltaTime);

Now i want to increment my score when circle completes rotation to 360 degree.

For that i have tried :

1) transform.rotation.z == 360

2) transform.Eulerangles.z == 360.

But this will not work as circle is continuous rotating with different speed.

So this condition will not satisfied. So what can be the another way to find complete rotation completion.

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

2 Replies

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

Answer by Veldars · Apr 11, 2015 at 06:02 AM

I think you can create some variable...

 private float _prevRotation = 0;
 private float _actRotation = 0;
 
 
 void Start() {
     _prevRotation = transform.rotation.z;
 }
 
 void Update {
 
   _actRotation = transform.rotation.z;
   if (_actRotation - _prevRotation >= 360) {
     // Do what you want...
 
     // Reset prevRotation
     _prevRotation = transform.rotation.z;
   }
   transform.Rotate( 0  , 0 , speed * Time.DeltaTime);
 }


I hope it's what you are looking for.

Comment
Add comment · Show 3 · 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 Ekta-Mehta-D · Apr 11, 2015 at 06:30 AM 0
Share

Ok. I will try and let you know. @Veldars

avatar image Ekta-Mehta-D · Apr 11, 2015 at 05:05 PM 0
Share

This is not working. i have checked.

avatar image Veldars · Apr 11, 2015 at 05:23 PM 0
Share

All right this code works for me (I've try it before sending it ^^)

 using UnityEngine;
 using System.Collections;
 
 public class Rotate : $$anonymous$$onoBehaviour {
 
     private bool     _isPos = true;
     private float _actRotation = 0;
     private float speed = 50f;
 
     void Update () {
         
         _actRotation = transform.rotation.z;
         Debug.Log(transform.rotation.z);
         if ((_actRotation < 0 && _isPos) ||  (_actRotation > 0 && !_isPos)) {
             // Do what you want...
             Debug.Log("Complete");
             // Reset prevRotation
             _isPos = !_isPos;
         }
         transform.Rotate( 0  , 0 , speed * Time.deltaTime);
     }
 }
 

I hope this will work for you

avatar image
1

Answer by hirenkacha · Apr 13, 2015 at 06:07 AM

@Veldars's code is also fine. If you want to check for EulerAngles then you can try this.

 using UnityEngine;
 using System.Collections;
 
 public class Rotator : MonoBehaviour 
 {
     private float currentRotation;
     private float speed = 50f;
 
     void Update () 
     {
         currentRotation = transform.rotation.eulerAngles.z;
 
         if(currentRotation>360-speed * Time.deltaTime || currentRotation==360)
         {
             Debug.Log("===Complete");
         }
 
         transform.Rotate( 0  , 0 , speed * Time.deltaTime);
     }
 }
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

20 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

Related Questions

2d detect 360 (backflip) rotation on z axis? 2 Answers

What is the most efficient way to rotate an object? 3 Answers

How can I rotate a gameobject with mouse drag? 1 Answer

Object doesn't turn at the desired rate 1 Answer

360° slerp horizontal rotation camera with the slider 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