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 ratamorph · Jul 21, 2014 at 12:30 PM · quaternions

Object rotation for a motorcycle stunts game

I'm trying to create a rotation for my bikes but I'm struggling with the quaternion construction.

What I need:

  1. The bike rotates on its local x axis (back flips, front flips, wheelies).

  2. The bike steers on its local y axis.

  3. Rolling is not permitted so no rotation on the z axis.

  4. Must be a single object, no hierarchy.

I tried creating my quaternion as such:

 Quaternion desiredRotation = Quaternion.Euler(flipsRotation, steeringRotation, 0);

The problem is that as I do flips and I'm at 90 degrees on the x axis the bike tries to flip on the z axis.

I tried some work around like this:

 float adjustedRoll = 0;
 float adjustedYaw = steeringRotation;
 
 //adjust angles if bike is flipped
 if(transform.up.y < 0)
 {
      adjustedRoll = 180;
      adjustedYaw = 180 + steeringRotation;
 }
 
 Quaternion desiredRotation = Quaternion.Euler(flipsRotation, adjustedYaw, adjustedRoll);

This sort of works but I still get some glitches. I'm sure there is a more elegant solution to this problem.

Any ideas?

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 ratamorph · Jul 25, 2014 at 02:02 PM 0
Share

I posted another question regarding getting the rotation angles on just 1 axis which is very related to my problem http://answers.unity3d.com/questions/756467/getting-object-rotation-on-just-1-axis.html

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Supershandy · Jul 25, 2014 at 02:37 PM

You can just lock off the angles by setting the rotation variable to zero.

E.g

 Var bike : Transform;
 
 Function Update ()
 
 {
     If (bike.up.y < 0)
     {
         AdjustedRoll = 180;
         AdjustedYaw = 180 + steeringRotation;
         bike.rotation.z = 0;
     }
 }

I can't guarantee anything though as I'm currently at work and can't test it.

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 ratamorph · Jul 26, 2014 at 08:00 PM

I fixed my issue! Here's how I calculated the final rotation:

 Vector3 pitchYawRoll = UtilityFunctions.GetPitchYawRollDeg(transform.rotation);
 
 Quaternion pitchRotation = Quaternion.AngleAxis(pitchYawRoll.x, Vector3.right);
 Quaternion yawRotation = Quaternion.LookRotation(steeringDirection, Vector3.up);
 
 Quaternion desiredRotation = yawRotation * pitchRotation;

The code for GetPitchYawRollDeg(Quaternion transform) is in my other question http://answers.unity3d.com/questions/756467/getting-object-rotation-on-just-1-axis.html

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 bhongleram · Jan 25, 2020 at 08:16 PM

Lock the z rotation constraint from inspector.

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 HaMrDev · May 04, 2020 at 07:23 PM

i need help with something , i am trying to check if the player's rotation is bigger or smaller than a number if it is i will end the game but if i start it it ends immediately
public class PlayerMovement : MonoBehaviour { public float sideWaysForce = 0.5f;

 protected JoyButton joybutton;

 protected JoyButtonRight joybuttonright;

 public Rigidbody rb;

 public float forward = 2100f;

public float sideWaysForceKEYBOARD = 0.7f;

 public AudioSource backgroundMusic;

protected Brake brake;

 protected Gas gas;

 private float increaseVolume = 0.005f;

 private float increasePitch = 0.0005f;

 public float maxSpeed = 1600f;

 public float minspeed = 0f;

 public float minspeedmultiplier = 1.45f;

 public Transform playert; 

 public float delay = 13f;


 public void Start()
 {
     backgroundMusic.Play();
     joybutton = FindObjectOfType<JoyButton>();
     joybuttonright = FindObjectOfType<JoyButtonRight>();
     gas = FindObjectOfType<Gas>();
     brake = FindObjectOfType<Brake>();
   
     
 }
 private void Update()
 {

    
     backgroundMusic.volume += increaseVolume;
     backgroundMusic.pitch += increasePitch;
     if (backgroundMusic.pitch > 1)
     {
         backgroundMusic.pitch = 1f;

     }
     if (transform.rotation.eulerAngles.x> 60) 
     {
         GameObject.Find("GameManager").SendMessage("Restart");

     }
     if (transform.rotation.eulerAngles.x > -60)
     {
         GameObject.Find("GameManager").SendMessage("Restart");

     }
 }
 void FixedUpdate()
 {


     if (brake.brakeispressed)
     {
         forward -= 70;
     }

     if (gas.Gasispressed)
     {
         forward += 70;
     }

     if (forward <= 400)
     {
         forward = forward + 70;

     }
     if (joybutton.Pressed)
     {

         rb.AddForce(-sideWaysForce , 0, 0, ForceMode.VelocityChange);
     }
     if (joybuttonright.PressedRight)
     {
         rb.AddForce(sideWaysForce , 0, 0, ForceMode.VelocityChange);

     }
     


     if (forward > maxSpeed)
     {
         forward = forward = maxSpeed; 

     }

     rb.AddForce(0, 0,forward * Time.fixedDeltaTime );

     if (Input.GetKey("a"))
     {
         rb.AddForce(-sideWaysForceKEYBOARD, 0, 0, ForceMode.VelocityChange);



     }
     if (Input.GetKey("s"))
     {
         forward = forward - 70;

     }
     if (Input.GetKey("w"))
     {
         forward = forward + 70;

     }
     if (Input.GetKey("d"))
     {
         rb.AddForce(sideWaysForceKEYBOARD, 0, 0, ForceMode.VelocityChange);

     }




     if (rb.position.y < -1f)
     {
         restartTimerAndScore();
         backgroundMusic.Stop();


     }
     if (rb.position.y > 3f)
     {
        
         restartTimerAndScore();
         backgroundMusic.Stop();
     }
     if (forward < minspeed)
     {
         forward = forward = minspeed * minspeed;
     }
    

 }
  

 public void restartTimerAndScore()
 {
     GameObject.Find("Player").SendMessage("restartTimer");
     GameObject.Find("SC").SendMessage("restartscore");
     FindObjectOfType<GameManager>().EndGame();
     

 }

}

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

25 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

Related Questions

Quaternions, Eulers, and Small Float Values? 0 Answers

Fixed tilt rotation on speed up problem 0 Answers

Position.z change to -20 when creating item 1 Answer

Change FirstPersonController to use global rotation values 0 Answers

Need help with storing Rotation in a Quaternion 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