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
2
Question by 12boulla · Jan 26, 2016 at 08:08 PM · 2drotationcarflip360-degrees

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

Hi,

So I am making a 2d car game and am trying to implement scoring points based on the amount of backflips completed. I am not sure how to calculate (once the car has left the ground) if it has completed a full 360 degree turn anti-clockwise to then score a point. Does anyone know how I detect this?

Any help is greatly appreciated, 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
1

Answer by Teravisor · Jan 26, 2016 at 08:40 PM

It's so simple... I don't know how you didn't thought of that...

  1. You can start counting it only when you change state from on-ground to airborne.

  2. Each frame add to some variable that counts how much you turned while airborne.

  3. Until you're out of airborne state. Then check which angle you've changed since 1. and score a point if you did do >=360 degree turn. Stop counting.

In order to check exactly counterclockwise and not just any angle, you need a simple math: angle between Vector(1,0) and Vector(x,y) is Mathf.Atan2(y,x); (returns from -180 to 180 degrees in radians so multiply by Mathf.Rad2Deg and check when it goes from -179 to +179 or just use RigidBody2D.inertia) then subtract previous value of same angle to find angle change. Positive will be counterclockwise and negative will be clockwise.

Comment
Add comment · Show 4 · 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 12boulla · Jan 26, 2016 at 09:00 PM 0
Share

How do I count how much I have turned? Could you give an example of it?

Thanks for the answer though, it answers most of my queries, thanks @Teravisor

avatar image Eno-Khaon 12boulla · Jan 26, 2016 at 09:12 PM 0
Share

One potential approach would be to save your previous rotation on a frame, then compare it with your new rotation at the end of the current frame. For that, you could use something like:

 Quaternion lastRotation = transform.rotation;
 // Apply rotational changes
 Quaternion rotationOnFrame = Quaternion.Angle(lastRotation, transform.rotation);

Or, in the case of using the physics engine, the process can be inverted, where the last frame's rotation is grabbed at the end of the script and the difference is compared before changing its value again.

avatar image 12boulla Eno-Khaon · Jan 26, 2016 at 09:21 PM 0
Share

Sorry for being a pain, but I am still confused. So do i set the lastRotationwhen I leave the ground and rotationOnFrame when I land again? Also, Quaternion.Angle is a float, not a Quaternion. How do I know the car has gone all the way round, and what if it goes more than 360 degrees? Thanks for the help @$$anonymous$$o $$anonymous$$haon

Show more comments
avatar image
0

Answer by noeyedeer321 · Sep 17, 2019 at 01:47 AM

Also have the same problem.

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

61 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

Related Questions

2D rotation and moving forward 2 Answers

Localscale-flipped 2D character retains original rotation since 5.4 2 Answers

2D rotation question 0 Answers

Rotate/Flip Image in Unity 2d using Virtual Joystick 1 Answer

Flip the player with arm rotation 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