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 /
  • Help Room /
This question was closed Dec 11, 2016 at 02:23 AM by Thomas-Hawk for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by Thomas-Hawk · Dec 10, 2016 at 09:20 PM · scripting problemphysicsrigidbodyeuleranglesupright

Keeping a rigidbody character upright, without constraining, grounded or otherwise, with slopes?

I have searched and searched for a solution, found many people looking for what seemed to be the same thing, but try as I might the solutions I found fell short. Once I got my character to get back upright relative to its individual offsets, but not in any sort of update function. Once, I got my character staying upright, but it going past my limits would reset it on all axis.

I have a character, that I was moving with a vector3 fetched from an on-screen joystick, seeking SM64-like controls. I badly want my character to align to the terrain it is standing on. I found some convoluted solutions involving raycasting, but what I think I'd rather work with is a physics based character, and somehow clamp how far it can rotate on the X and Z axis, with physics. ![alt text][1]

Desired result: [1]: /storage/temp/83796-picc.png

As you can see, I don't want to constrain the rigidbody, because I actually need it to rotate on all axis. I just want to limit, or clamp, how far the character can rotate, so that if it were to climb a slope, my character would lean with the slope ( i drew an armless stick figure to show what I mean, but my actual character is a rabbit which is on all fours, so my capsule collider is on the Z axis).

Here's a little code I had in my LateUpdate, derivative from something I found on an old forum post.

         if (transform.localRotation.eulerAngles.z > 0.25f) {

             transform.localRotation = Quaternion.Euler(transform.localRotation.x, transform.localRotation.y, 0.25f);

         }
 
         if (transform.localRotation.eulerAngles.x > 0.25f) {

             transform.localRotation = Quaternion.Euler(0.25f, transform.localRotation.y, transform.localRotation.z);
         }

However, this would just seem to lock my rotation to world-relative one, where I was still moving forward and back relative to my own rotation, but snapped onto one axis. Debug logs would show the limit triggering, no console errors, but my character would keep on turning and topple over.

Any resources would help, a push in the right direction, or a tutorial that accomplishes this (I have yet to find one).

picc.png (9.2 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 Bunny83 · Dec 11, 2016 at 05:34 AM 0
Share

I recommend watching this GDC talk about procedural animation and character control. It's in general not a good idea to let physics control your rotation around x and z.

1 Reply

  • Sort: 
avatar image
0

Answer by DroidifyDevs · Dec 10, 2016 at 10:28 PM

This is what you need:

 this.gameObject.transform.rotation = Quaternion.Euler(0, this.gameObject.transform.rotation.y, this.gameObject.transform.rotation.z);

That way the X rotation will always be the same and won't tip over. You can change the 0 to whatever angle you need to keep.

Also, the image you posted doesn't work (for obvious reasons).

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 Thomas-Hawk · Dec 11, 2016 at 12:02 AM 0
Share

DroidifyDevs, thank you for answering but maybe my problem wasn't communicated properly.

I want my character and it's rotation to be affected by physics, I just don't want it rotating past certain degrees on certain axis.so that the character might slide rather than roll down or up a slope effectively aligning it with the terrain its standing on

avatar image DroidifyDevs Thomas-Hawk · Dec 11, 2016 at 01:35 PM 0
Share

So then you can do if (this.gameObject.transform.rotation.x > $$anonymous$$axAmount) { this.gameObject.transform.rotation = Quaternion.Euler($$anonymous$$axAmount, this.gameObject.transform.rotation.y, this.gameObject.transform.rotation.z); }

And do the same for the other tilt direction.

avatar image Bunny83 DroidifyDevs · Dec 11, 2016 at 02:43 PM 0
Share

Your code doesn't make much sense as rotation.x is not an angle! You're dealing with a Quaternion here. You probably ment to use transform.eulerAngles.x. However the euler angles representation of a rotation is not very reliable.

Follow this Question

Answers Answers and Comments

113 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

Related Questions

Using rb.velocity causes low gravity. 2 Answers

Adding force to a rigidbody opposite to the direction of a rotating weapon 0 Answers

Applying force to local forward on rotating object 0 Answers

Bunch of instantiated RBs blows away 0 Answers

how to dostraight ball throwing objects from returning? 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