• 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 MrNegaBlox · Jun 17, 2017 at 02:16 AM · scripting problemaccelerationprocedural animation

Acceleration Tilt

So I am trying to recreate the character controller in overgrowth based on the GDC talk one of the devs gave: http://www.gdcvault.com/play/1020583/Animation-Bootcamp-An-Indie-Approach

I am trying to implement the acceleration tilt part. I have working calculations of the proper tilt vector, which is a vector from the object's base which tilts (from Vector3.up) in the direction of the acceleration. However, I don't know how to actually have the gameobject tilt towards the vector direction while maintaining a set forward direction.

the code is really unclean, sorry

     Vector3 velocity = rb.velocity;
     

     Vector3 a = (rb.velocity - lastVelocity) / Time.fixedDeltaTime;
     lastVelocity = rb.velocity;

 Vector3 direction = new Vector3 (a.x, 0, a.z);
     Vector3 axis = Quaternion.AngleAxis(90, Vector3.up) * direction;
    

     targetRot = Vector3.up;

     if (Mathf.Abs(velocity.x) > 0.2f || Mathf.Abs(velocity.z) > 0.2f)
     {
         Vector3 vel = new Vector3(velocity.x, 0, velocity.z);
         targetForward = vel;
     } 

     if (Mathf.Abs(direction.x) > 0.2f || Mathf.Abs(direction.z) > 0.2f)
     {
         targetRot = Quaternion.AngleAxis(maxTiltAngle, axis) * targetRot;
     }
     com.transform.rotation = Quaternion.Slerp(com.transform.rotation, Quaternion.LookRotation(targetForward, targetRot), Time.fixedDeltaTime*5); //It's this line that is the problem

I know now that LookRotation isn't gonna work, because it only tilts around the forward vector, but I could not find another stable way to do it. Is there any way of setting both Transform.forward and Transform.up while having one not overwrite the other?

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 MrNegaBlox · Jun 17, 2017 at 01:21 PM

Okay, so I just looked into quaternions, and I just found a solution, so I'm putting it here for those who wants to learn to do this as well. Basically, with quaternions, the xyz components define an axis, and the w component is the amount of rotations around that axis, and multiplying quaternions combine rotations as if it were one after the other.

So I did this:

 Quaternion.LookRotation(targetForward)*new Quaternion(axis.x, axis.y, axis.z, maxTiltAngle*10f)

So basically this does 2 things, first it makes the gameobject point in the forward direction, then I used another quaternion to have it rotate around an axis that is 90 degrees from the acceleration direction. the *10f is a wierd thing where the BIGGER the w component is, the smaller the rotation.

Then combine this with a slerp, and youve got it.

NOTE: however, it is still really finicky, pressing buttons rapidly make it snap back and forth. otherwise, it was the intended result.

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 toddisarockstar · Jun 17, 2017 at 03:32 AM

the video link isnt loading. if you are just trying to make a character tild forward. I think you are making this much more difficult than it needs to be.

you don't need transform.forward. All you should need to do is just change the x axis of the character's rotation!!!

here would be the raw idea:

 float xxx;
 float speed;
 
 void Start(){
 speed=10f;
 xxx=0f;
 }
 
 void Update () {
 
         if (your velocity is greater than whatever) {
             if (xxx < 30f) {//max angle adjustment here
                 xxx += Time.deltaTime*speed;
             }
         } else {
             if (xxx > 0f) {
                 xxx += -Time.deltaTime*speed;
             }
         }
 
         transform.eulerAngles = new Vector3 (xxx,transform.eulerAngles.y, transform.eulerAngles.z);
 }



I would reccomend making the speed variable get bigger according the the acceleration and possibly your max angle too to make things look smooth. but this is the basic untested idea.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

101 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

Related Questions

How do i make my character accelerate over time?? And a better movement script would help too. 0 Answers

Targeting system, can select but won't deselect... 0 Answers

Wheel collider physics - something I'm missing? 0 Answers

building error in my video project apk 0 Answers

Can't access Halo component 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