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 laisch · May 09, 2015 at 03:16 PM · rotationlocalflip

Detecting 360 degree spin on local y axis

alt text

Maybe it's a simple questioan and there are some similar topics here, but nothing really helped me and I am stucked with this problem for 3 days now.

I have got an physics driven object and i want to track its "local y" or transform.up rotation on an triggered event. I want to know if it did a 360 degree spin. A good example for this problem is when the player makes a frontflip and you also want to know if he did some spins within.

Thx

issue.jpg (31.1 kB)
Comment
Add comment · Show 1
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 laisch · Jun 09, 2015 at 08:14 AM 0
Share

No one? Still got stucked with this problem.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Mark Gossage · Jun 09, 2015 at 01:52 PM

((Expecting an answer in 35 minutes is a bit much!))

To detect ANY rotation, you can just compare transform.localRotation to the previous rotation using Quaternion.Angle()

If you wanted for just one axis, you could use transform.localRotation.eularAngle and compare to previous angle. Use a Mathf.DeltaAngle to overcome the 0/360 issue.

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 laisch · Jun 11, 2015 at 09:40 AM 0
Share

((Expecting an answer in 35 $$anonymous$$utes is a bit much!))

It was asked one $$anonymous$$onth and 35$$anonymous$$s ago ;)

Quarternion.angle was my first intention too, but here I have the problem if i do just a horizontal spin it will work, but if I do a spin combined with a front or backflip it tracks just the delta on an different axis.

avatar image
1

Answer by Immanuel-Scholz · Jun 09, 2015 at 09:39 AM

So, if I understand you correctly, you have an triggered event from outside, when the tracking begins (e.g. the biker jumps in the air). From then, you want to track and get informed when the bike spinned 360° in any direction, right?

Then here is something out of the blue (means: I didn't even try to compile it ;)) that might get you an idea how I would approach this.

 class DegreeTracker
 {
 
   float angleSoFar, angleLastFrame;
 
   void Start() { enabled = false; } // no tracking by default
 
   // called from somewhere when the tracking begins
   public void StartJump()
   {
     angleSoFar = 0;
     angleLastFrame = transform.localEulerAngles[1];
     enabled = true;
   }
 
   void Update()
   {
     float angle = transform.localEulerAngles[1];
     angleSoFar += angleLastFrame - angle;
     angleLastFrame = angle;
     if (angleSoFar > 360)
     {
       // code for 360 clockwise comes here
 
       enabled = false; // finished circle, so disable tracking
     }
     else if (angleSoFar < 360)
     {
       // code for 360 counter clockwise comes here
 
       enabled = false; // finished circle, so disable tracking
     }
   }
 }

Basically, you remember the angle from last frame and sum up the difference each frame. If you hit > or < 360, you got your circle.

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 fzawd · Jun 09, 2015 at 11:10 AM 0
Share

Simply subtracting the values from eulerAngles parameters will not work. You would expect (1 degrees) $$anonymous$$us (-1 degrees) to be (2 degrees), while the plain subtraction gives you (-358 degrees).

Hope this helps!

avatar image laisch · Jun 11, 2015 at 09:54 AM 0
Share

I have some problems with the local and global eulerAngles. Here I got the same values...

I don't know if this helps: The player object has some childs, but the tracked object is the parrent. when I try to track one of the child objects, there is a difference on localEuler, but until they a re not rotating relative to it's parent they don't give any deltas. $$anonymous$$aybe I have prolems to understand the difference between localEuler and global ones.

Is there an opposite function like Quarternion.AngleAxis but wich gives me the degrees as return value on an fixed Axe?

avatar image Immanuel-Scholz · Jun 11, 2015 at 10:09 AM 0
Share

Local rotation is simply the rotation relative to the parent of the object. This is what you see in the "Transform" component when you open the object in the Unity "Inspector" window.

The global rotation is.. well.. the rotation in the world. So that is what you see when you see the object in the scene view. If its tilted, then its global rotation is tilted.

So if you want to track a global rotation (means: You don't care which parents of the tracked object gets rotated, as long as you know when the overall object finally spun one circle), then you need to track "eulerAngles" ins$$anonymous$$d of "localEulerAngles".

"eulerAngles" is also the desired "opposite function" you where looking at (as long as the x- and z-rotation is 0).

And fzawd is right - you might experiment with $$anonymous$$athf.DeltaAngle() ins$$anonymous$$d of substracting values to get around the 360->0 border problem..

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Get raycast to ignore rotational axis 2 Answers

Flip over an object (smooth transition) 3 Answers

Camera Rotation stay behind player and not flip 2 Answers

Sprite disapears when moving left 2 Answers

rotate vector around local axis 2 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