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 Janibasha · Jul 04, 2018 at 09:41 AM · unity 5

How to check car has rotated a complete rotation i.e 360. so I can add 1 int value to score.. https://www.youtube.com/watch?v=9Ztd1XXmUGI like in this game Thanks.

How to check car has rotated a complete rotation i.e 360. so I can add 1 int value to score.. https://www.youtube.com/watch?v=9Ztd1XXmUGI

Vector3 strtAngle; Vector3 ChangedAngle; int ang;

 float z_angle;

 private void Start()
 {
     ///////////////
     strtAngle = new Vector3(0, 0, transform.rotation.eulerAngles.z);

     ang = 0;

 }
 private void Update()
 {
     z_angle = transform.rotation.eulerAngles.z;
     ChangedAngle = new Vector3(0, 0, transform.rotation.eulerAngles.z);
   
     Debug.Log("finalAngle" +ChangedAngle);

     float angle = Vector3.Angle(strtAngle, ChangedAngle);
     Debug.Log("angle: " + angle);


    // Vector3 targetDir = ChangedAngle - transform.chan;
    // float angle = Vector3.Angle(targetDir, transform.forward);

     if (angle > 350f)
         print("Add score stuff.....!!!");
 }
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 Janibasha · Jul 05, 2018 at 03:48 PM 0
Share

the value 360 is cant catch it. may be bcz of FPS if u check please help me.

OnCollisionEnter(Collision collisionInfo) & void OnCollisionExit(Collision collisionInfo) some times inAir not getting true after colliding ground so i used raycast to check ground.

void IsGrounded() { RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, 1.0f, lineLayer); // Debug.Log("Collided with:" + hit.collider.name); if (hit.collider != null && hit.collider.tag == "Ground") { isGrounded = true; // Debug.Log("GROUNDED"); } else { isGrounded = false; Debug.Log(" not GROUNDED"); } Debug.DrawRay(transform.position, Vector3.down, Color.green); }

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Vincent1236 · Jul 04, 2018 at 10:41 AM

I think you are almost there. One thing, that will depend on how you want it, but I think you need to decide. Which is when the player can start spinning for points, which I think should be when leaving/not touching the track anymore (ie in air). I assume this is done by tagging ground as 'ground'

 [SerializeField]
 float previousAngle, currentAngle, flipAngle;
 [SerializeField]
 bool inAir;
 [SerializeField]
 int _360s = 0;

 private void Update()
 {
     if (inAir)
     {
         currentAngle = transform.eulerAngles.z;
         // Calculate the angle the bike has turned since the last frame and add to total rotation for this jump
         flipAngle += Mathf.DeltaAngle(currentAngle, previousAngle);

         previousAngle = currentAngle;
     }
 }

 void OnCollisionExit(Collision collisionInfo)
 {
     Debug.Log("No longer in contact with " + collisionInfo.transform.name);
     if (collisionInfo.gameObject.tag == "Ground") // you need to determine what counts as track/ground
     {
         inAir = true;
         _360s = 0;
         flipAngle = 0;
         previousAngle = transform.eulerAngles.z;
     }
 }

 void OnCollisionEnter(Collision collisionInfo)
 {
     Debug.Log("Now contact with " + collisionInfo.transform.name);
     if (collisionInfo.gameObject.tag == "Ground") // you need to determine what counts as track/ground
     {
         inAir = false;
         // You can decrease this ever so slightly, to accomodate for slopes. Or just add floats that account for take-off and landing-slopes
         _360s = (int)flipAngle / 360;
         if (_360s > 0)
             Debug.Log("You did " + _360s + " front flips!!!");
         else if (_360s < 0)
             Debug.Log("You did " + _360s + " back flips!!!");
     }
 }

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
avatar image
0

Answer by Janibasha · Jul 05, 2018 at 03:33 PM

Thanks for fast reply, I wrote the same but in the update function the condition not checking and more this function cannot catch the condition value

if (Mathf.Abs(strtAngle - currentAngle) > 360) { // no of rotations (count here) }

the value 360 is cant catch it. may be bcz of FPS if u check please help me.

OnCollisionEnter(Collision collisionInfo) & void OnCollisionExit(Collision collisionInfo) some times inAir not getting true after colliding ground so i used raycast to check ground.

void IsGrounded() { RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, 1.0f, lineLayer); // Debug.Log("Collided with:" + hit.collider.name); if (hit.collider != null && hit.collider.tag == "Ground") { isGrounded = true; // Debug.Log("GROUNDED"); } else { isGrounded = false; Debug.Log(" not GROUNDED"); } Debug.DrawRay(transform.position, Vector3.down,Color.green); } https://www.youtube.com/watch?v=9Ztd1XXmUGI

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 Vincent1236 · Jul 06, 2018 at 07:19 AM 1
Share

Will only be able to do some more work on this after the weekend as I am away. Yeah as long as you have a ground check works, whether it is raycast or collision based doesn't matter. In the mean time try using ins$$anonymous$$d of > 360 try > 300 or a smaller angle and see if the if passes.

If that works, just set srtAngle = currentAngle; inside the if. Otherwise you will get like thousands of logs/rotation counts

avatar image Janibasha · Jul 09, 2018 at 08:34 AM 0
Share

if do ins$$anonymous$$d of > 360 try > 300 or a smaller angle in update function the angle value goes to 300, 305,310,...350 . it skips different values in different times. may be bcz of frame rate..Please help .. i do try , THnks

avatar image Vincent1236 Janibasha · Jul 09, 2018 at 09:30 PM 0
Share

Okay check my original answer. I have updated it. Good luck further! Oh and the idea will still work, no matter how you implement your grounding check as long as it works

avatar image Janibasha Vincent1236 · Jul 12, 2018 at 02:16 PM 0
Share

not working...!!! getting rotation angle but not in one direction i.e when bike flips anti clock direction and not checking angle at <360 ... I checked last 2 days but can't find..plz help me. maybe u did not test the code.. ;-(( if u test I hope u definitely get the 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

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

I can not import the .exr file into my project 0 Answers

How to center a rect in a gui.label 1 Answer

How to move object base on where it is facing? 0 Answers

How backward-compatibly write NotificationServices in Unity 2 Answers

My cam not open using webcamtexture 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