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 Tuah · Jun 08, 2010 at 06:53 AM · rotationgravitysystemlocomotion

Making this rotation instant...

I've kinda burned myself out working so much on these scripts, and I haven't been able to figure this part out. I have this section of the Locomotion project which aligns a character to the center of gravity. So if the character is running around the planet, he'll rotate along it, and gravity pulls him "down". But sometimes if he goes too fast, the rotation direction won't work quickly enough. And since gravity pulls him to his "down", (and his "down" is pointing some other direction now) he'll go flying in another direction.

I can fix the gravity issue later, but it's this rotation that's really bugging me.

What's a good method of making this transition instant?

private void AdjustToGravity() { int origLayer = gameObject.layer; gameObject.layer = 2;

     Vector3 currentUp = transform.up;
     //Vector3 gravityUp = (transform.position-gravityCenter).normalized;

     float damping = Mathf.Clamp01(Time.deltaTime*5);

     RaycastHit hit;

     Vector3 desiredUp = Vector3.zero;
         if ( Physics.Raycast(transform.position, transform.up*-1, out hit, 30.0f, groundLayers.value) ) {
             desiredUp += hit.normal;
         }

     desiredUp = (currentUp+desiredUp).normalized;
     Vector3 newUp = (currentUp+desiredUp*damping).normalized;

     float angle = Vector3.Angle(currentUp,newUp);
     if (angle>0.01) {
         Vector3 axis = Vector3.Cross(currentUp,newUp).normalized;
         Quaternion rot = Quaternion.AngleAxis(angle,axis);
         transform.rotation = rot * transform.rotation;
     }


     gameObject.layer = origLayer;
 }

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
Best Answer

Answer by Ryder · Jun 08, 2010 at 07:23 AM

I don't know much about character animation... but, if the character is a rigid body, you can turn on "interpolate" in the Rigidbody portion in the inspector window for your character... that might work.

Good luck!

Ryder

Comment
Add comment · Show 1 · 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 Tuah · Jun 08, 2010 at 04:10 PM 0
Share

This made the rotation exactly as I needed. As $$anonymous$$r. Johansen said, as "instant" as I had wanted ended up being less than my already-low expectations.

This system is going to be more of a "suction-cup-boot" system as mentioned, since it will only be activated at high speeds.

Thanks to both of you!

avatar image
1

Answer by runevision · Jun 08, 2010 at 08:27 AM

These lines are responsible for the smoothing:

desiredUp = (currentUp+desiredUp).normalized;
Vector3 newUp = (currentUp+desiredUp*damping).normalized;

If you want an instant transition, change it to this instead:

Vector3 newUp = desiredUp.normalized;

However, note that this may not actually produce desirable results.

  1. Your character will "pop" into a new alignment whenever he walks onto a surface with a different normal.

  2. This system will not catch all cases no matter if it's smooth or not. If a character walks off a 90 degree edge of a roof, he will never "see" the wall and thus not be aligned to walk on the wall but rather just fall down.

  3. The system is very bad when the character is jumping / in the air - it's potentially worse the further away from the surface he is. In worst case it can cause jitter / oscillation of the rotation.

In conclusion, the method should be thought more to simulate "suction cup boots" / "magnetic boots" that only have any effect while on a surface - and has limitations even then, and it's really not very suitable for simulating gravity.

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

No one has followed this question yet.

Related Questions

Rigidbody unaffected by standard unity gravity and script gravity 3 Answers

Accessing local system ( File Browser ) 2 Answers

Locomotion Problem with JumpAndIdle waitanimation stops for a few seconds! 1 Answer

How can I rotate and move a cylindrical rod from one side with respect to other side? 1 Answer

How do I reference an object's rotation through an attached script? 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