Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by Nemarques · Jan 19 at 01:47 PM · rotationtransformquaternioncarnormals

Car weirdly flips 180 degrees while rotating to ground normal

Hey recently I bumped into a problem that I am not being able to fix. Basically I have a car that is composed my 3 transforms: Car -> Normal -> Mesh. The Normal is child of the car and the mesh is child of the Normal. I want this car to rotate accordingly to the ground normal but also rotate it to steer the car.


The current approach is that I rotate the Car transform on the Y axis to steer and then modify the Normal up vector to correspond to the ground normal. In most cases this is working really well. The problem is when my car is doing a loop(hotwheels kind of thing) and turns upside down. In this moment my car has bug which makes it instantly rotate 180 degrees, in the gif you can see the rotation going from 179 to -180, which is causing weird behaviours on my camera and the car handling itself.


Here is the issue being reproduced in a scene where I rotate the green car and make the Normal transform of the red car match its up vector.

GIF demonstrating the problem (Imgur)


Here is the current code:

 Car.eulerAngles = Vector3.Lerp(Car.eulerAngles, new Vector3(0, Car.eulerAngles.y + TurnYAmount, 0), Time.deltaTime * TurnSpeed);
 
 Normal.up = Vector3.Lerp(Normal.up, UpCar.up, Time.deltaTime * NormalChangeSpeed);
 Normal.Rotate(new Vector3(0, Car.eulerAngles.y, 0));

I have already tried using Quaternion.LookRotation and Quaternion.FromToRotation, but it didn't solve my problem and created more issues, one of them was that the car stopped to rotating more than 90 degrees.

Here is how the normal is calculated:

 if(frontLeftHitFlag && frontRightHitFlag && backLeftFlag && backRightFlag)
 {
        Vector3 a = backRightHit.point - backLeftHit.point;
        Vector3 b = frontRightHit.point - backRightHit.point;
        Vector3 c = frontLeftHit.point - frontRightHit.point;
        Vector3 d = backRightHit.point - frontLeftHit.point;
  
       // Get the normal at each corner
       Vector3 crossBA = Vector3.Cross(b, a);
       Vector3 crossCB = Vector3.Cross(c, b);
       Vector3 crossDC = Vector3.Cross(d, c);
       Vector3 crossAD = Vector3.Cross(a, d);
  
      Debug.DrawRay(backRightHit.point, Vector3.up);
      Debug.DrawRay(backLeftHit.point, Vector3.up);
      Debug.DrawRay(frontLeftHit.point, Vector3.up);
      Debug.DrawRay(frontRightHit.point, Vector3.up);
 
      Vector3 normal = ((crossBA) + crossCB + crossDC + crossAD).normalized;
 }


Sorry for the long post, any help is highly appreciated.

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 andrew-lukasik · Jan 21 at 01:59 PM 0
Share

This is because cross product of two parallel vectors is zero.

0 Replies

· Add your reply
  • Sort: 

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

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

How to use Quaternion.Slerp with transform.LookAt? 3 Answers

Questions about Rotations in unity 1 Answer

Quaternion.RotateTowards for camera positions is buggy 1 Answer

Transform.Rotate with dynamic values 1 Answer

Auto level an object 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