• 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
Question by jRocket · Jul 10, 2012 at 08:56 PM · animationblendingrun

8-Way Animation Blending

I've made some run animations for a character and I'm having some difficulty implementing them. There are 8 separate animations that each correspond to a possible run direction using the WASD keys. They are forward, back, left strafe, right strafe, and the four in-between animations. Just using the four main animations(forward, back, left, right) would be easy - just set the weight to vertical and horizontal input, but I can't seem to wrap my head around how to implement the in-between animations. I am using Input.GetAxis for the input, so the input will be smoothed.

Any advice on how to proceed with this?

Comment

People who like this

0 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 reptilebeats · Jul 10, 2012 at 09:05 PM 0
Share

im personally waiting for unity 4 as there is a new animation system being introduced. not very helpful right now but just thought i would let you know if you didnt know

2 Replies

· Add your reply
  • Sort: 
avatar image

Answer by Piflik · Jul 10, 2012 at 09:42 PM

In my game, I blend the animations (6, since I am on a hex grid) based on the angle between the look direction and the move direction, not directly via the input.

 function Update () {
  lastPos = curPos;
  curPos = transform.position;
  
  if(curPos != lastPos){
  curAngle = Vector3.Angle((curPos - lastPos).normalized, transform.forward);
  clockwise = angleDir(transform.forward, (curPos - lastPos).normalized, Vector3.up);
  if(curAngle < 30)
  animation.CrossFade("walk_F", 0.1);
  else if(curAngle > 30 && curAngle < 90 && clockwise < 0) 
  animation.CrossFade("walk_FL", 0.1);
  else if(curAngle > 30 && curAngle < 90 && clockwise > 0) 
  animation.CrossFade("walk_FR", 0.1);
  else if(curAngle > 90 && curAngle < 150 && clockwise < 0) 
  animation.CrossFade("walk_BL", 0.1);
  else if(curAngle > 90 && curAngle < 150 && clockwise > 0) 
  animation.CrossFade("walk_BR", 0.1);
  else if(curAngle > 150) 
  animation.CrossFade("walk_B", 0.1);
  }
  
  if(curPos == lastPos)
  animation.CrossFade("idle", 0.1); 
 
 function angleDir(fwd: Vector3, targetDir: Vector3, up: Vector3) {   //determines CW or CCW
  var perp: Vector3 = Vector3.Cross(fwd, targetDir);
  var dir: float = Vector3.Dot(perp, up);
  
  if (dir > 0.0) {
  return 1.0;
  } else if (dir < 0.0) {
  return -1.0;
  } else {
  return 0.0;
  }
 }


There are no real blends between the animations here, since the player can only move in distinct directions, but it should be quite simple to implement...

Comment
Fattie

People who like this

1 Show 0 · 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

Answer by ricardo.ch · Oct 27, 2012 at 08:26 AM

What you want to do is use animation.Blend("animname", weight) and calculate your weight depending on what's important for you.

For us, we had a 4 way blend and we use the heading angle to calculate the correct blend weight:

  1. get blending angle in radians

  2. calculate sine and cosine

  3. save sign of sine and cosine

  4. animation.blend("forward", Mathf.Clam01(cosSign * cosinevalue^2))

  5. animation.blend("up", Mathf.Clam01(sineSign * sinevalue^2))

  6. animation.blend("back", Mathf.Clam01(cosSign cosinevalue^2 -1))

  7. animation.blend("down", Mathf.Clam01(sineSign sinevalue^2 -1))

This will give you values between 0-1 for each animation and will let you blend between.

Comment

People who like this

0 Show 0 · 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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation layers: Am i limited to only one layer per animation? 0 Answers

Getting weird behaviour when blending animations of behaviour fields 1 Answer

play animation when moving,and idle animation when stand still 1 Answer

animation blending with only 1 animation 2 Answers

Basic Animation FPS Questions 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