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 Lypheus · Jun 13, 2014 at 09:42 PM · rotationmecanimik

Mecanim IK Foot Rotation

I am working on some foot placement and so far have my characters feet aligning to the ground nicely, however the code snipet I rely on to do this:

Quaternion footRotation = Quaternion.LookRotation( Vector3.Exclude( hit.normal, transform.forward ), hit.normal );

forces the foot to always face the same direction as the transform. What I'd like to do here is to have the foot point in the direction it normally would before applying IK rotation weight.

Seems like that would require "transform.forward" in the above snipet to change, but i'm unsure of what to use. If i grab the bone transform for the foot and use its forward, things go all wrong :). Also tried some Vector3.Cross calls with the foot up and transform forward, etc... some combinations come close but still fail.

Just for a visual on what happens with this code so far, here are two SS's:

  1. Without IK (natural foot rotation at idle): http://screencast.com/t/N5ZVh5NSzzPu

  2. With IK (facing transform forward): http://screencast.com/t/2obcpS7VD

I'd like to have the Vector3.Exclude working so that the foot is planted using IK as in (2) above, but uses the animations foot rotation (on the yaxis?) as in (1).

Can someone with some strong math skills help me out here :)?

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 christoph_r · Jun 13, 2014 at 10:50 PM

Interesting question! What you apparently want to do is restrict the IK to the actor's x axis. Here's how I'd do it:

  1. Get the cross product of hit.normal and transform.right which results in a vector that is basically the slope corrected transform.forward.

  2. Get the quaternion for the rotation between your actor's transform.forward and the vector calculated in 1.) by using Quaternion.FromToRotation.

  3. Multiply your foot's transform.rotation with the quaternion resulting from 2 (which basically 'adds' these rotations).

I have not tested this myself, but I think it should work that way.

Comment
Add comment · Show 2 · 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 Lypheus · Jun 14, 2014 at 12:57 AM 0
Share

Gave that a shot, but it turns out painful looking :) :

SS: http://screencast.com/t/Z8UYvUa2G8

Code:

 Vector3 slopeCorrected = Vector3.Cross( hit.normal, transform.right );
 Quaternion slopeForward = Quaternion.FromToRotation( transform.forward, slopeCorrected );
 Quaternion footRotation = foot.rotation * slopeForward;
  

I was able to get something really close, using this:

 Quaternion footRotation = Quaternion.LookRotation( Vector3.Exclude( hit.normal, foot.up ), hit.normal );

But it is just a bit off if you rotate around, the feet don't quite stay put.

avatar image christoph_r · Jun 14, 2014 at 11:50 AM 0
Share

That result is extremely weird because on a flat surface, slopeCorrected should be 0. Well... how about:

     Vector3 slopeCorrected = Vector3.Cross( hit.normal, foot.right );
     Quaternion footRotation = Quaternion.LookRotation(slopeCorrected, hit.normal);
avatar image
1

Answer by Lypheus · Jun 20, 2014 at 03:50 AM

Ok interesting, this does what appears to be the exact opposite of the desired effect, maybe negate something in it?

http://screencast.com/t/nLzek7KU4aS

I seem to have it fixed with using:

Vector3 slopeCorrected = Vector3.Cross( hit.normal, foot.right ); Quaternion footRotation = Quaternion.LookRotation( Vector3.Exclude( hit.normal, slopeCorrected ), hit.normal );

So that'll do! Now its time to debug the "pop" i get with that foot twisting about lol, probably something to do with my code trying to predict for walking to enable/disable where clipping is not involved (i.e. avoid dragging feet).

Thanks!

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 christoph_r · Jul 01, 2014 at 06:33 PM 0
Share

Good to hear! And looks like it should be Vector3.Cross (foot.right, hit.normal) then (keeping in $$anonymous$$d that the cross product is anti commutative, i.e. its sign switches if you change the order of factors. Using that and dropping the Exclude part should improve performance a little bit (and make the code more compact).

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

22 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

Related Questions

Problem with rotations and IK 0 Answers

How to Aim Animator.SetIKRotation() to direction WRT hand bone rotation offset 0 Answers

How do you manually override mecanim's interpolation with rotations? 2 Answers

Mecanim ik curve 0 Answers

How to grab, pick and place an object to other location using Mecanim IK Script 2 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