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 tohmjudson · Jan 27, 2013 at 10:42 PM · mecanimcurves

Mecanim Curves not Registering in Unity Pro 4

Hi all,

I have followed the video tut here: https://www.youtube.com/watch?v=Xx21y9eJq1U

Add I am able to do all he animations, with the corrected script found here: http://answers.unity3d.com/questions/350104/mecanim-tute-problem.html

I have added a new animation to climb a box from Unity Asset Server called Run_JumpUpHigh_Run, I am able to trigger the animation and get it to move over the box... but...

Now to the question: I cannot get the new curves I have created to register with the capsule collider. The curves work with the JumpRollRun animation, but no matter what I add, its not changing the capsule collider at all. I have the Curves ColliderHeight and ColliderY attached to the animation clip What am I missing?

Below is the Script, my addition is between the //!!!!!!!!!!

(I am OK a JS, but the BotCrtl is C# and I must be missing something)

 using UnityEngine;
 using System;
 using System.Collections;
  
 [RequireComponent(typeof(Animator))]  
 [RequireComponent(typeof(CapsuleCollider))]  
 [RequireComponent(typeof(Rigidbody))]  
  
 public class BotCtrl : MonoBehaviour {
  
     [System.NonSerializedAttribute]
     public bool gotWrench;
  
     protected Animator animator;
     CapsuleCollider col;
     float h;
     float v;
     AnimatorStateInfo baseCurrentState;
     AnimatorStateInfo baseNextState;
     AnimatorStateInfo otherMovesCurrentState;
  
     public float DirectionDampTime = 0.15f;
     public float AnimSpeed = 1.2f;
     public float MoveSpeed = 1.5f;
     public float rotSpeed = 90.0f;
     public float JumpHeight = 70.0f;
     public bool useCurves;
     Transform grabbableObj;
  
     void Awake(){
        if(gameObject.tag != "Player")
          gameObject.tag="Player";
     }
  
     void Start () {
  
        animator = GetComponent<Animator>();
        animator.speed=AnimSpeed;
  
        if(animator.layerCount>1){
          animator.SetLayerWeight(1,1.0f);
        }
        col = GetComponent<CapsuleCollider>();
  
        grabbableObj = GameObject.FindWithTag("grabbable").transform;
     }
  
     void FixedUpdate () {
  
        // Grab Input each frame
        h = Input.GetAxis("Horizontal");
         v = Input.GetAxis("Vertical");  
  
        if(animator){
          // Set Speed and Direction Parameters to H and V axes
          animator.SetFloat ("Speed", v);
          animator.SetFloat("Direction", h, DirectionDampTime, Time.deltaTime);
  
          // Set variables for info on states
          baseCurrentState = animator.GetCurrentAnimatorStateInfo(0);
          baseNextState = animator.GetNextAnimatorStateInfo(0);
  
          if(animator.layerCount>1){
           otherMovesCurrentState = animator.GetCurrentAnimatorStateInfo(1);
          }
  
          //Trigger Jump if we are running
             if(baseCurrentState.IsName("Base.Locomotion")){
           if(Input.GetButtonDown("Jump")){
               animator.SetBool("Jump", true );   
           }
          }
          // Are we in idle state in Base Layer? set actions
          else if(baseCurrentState.IsName("Base.Idle")){
           // allow pivot on spot with Horizontal axis keys
           transform.Rotate (new Vector3(0,h*Time.deltaTime*rotSpeed,0));
  
           // make fire button cause a Wave during idle
           if(Input.GetButtonDown("Jump")){
               animator.SetBool("Wave", true );
           }
          }
          else if(baseCurrentState.IsName("Base.idleGrab")){
           // allow pivot on spot with Horizontal axis keys
           transform.Rotate (new Vector3(0,h*Time.deltaTime*rotSpeed,0));
           animator.SetBool("Grab", false );
          }
          else if(baseCurrentState.IsName("Base.Jump") && !animator.IsInTransition(0)){
           // Reset our parameter to avoid looping
                 animator.SetBool("Jump", false);
  
           // allow half as much rotation during jump
           transform.Rotate (new Vector3(0,h*Time.deltaTime*rotSpeed*0.5f,0));
  
           if(useCurves){
               //set the collider height and Y center during the jumps, based on curves
               col.center=new Vector3(0, animator.GetFloat("ColliderY"), 0);  
               col.height=animator.GetFloat("ColliderHeight");
  
               //add extra force to main jump
               rigidbody.AddForce(Vector3.up * animator.GetFloat("Jumper") * JumpHeight);
           }
          }    
          else if(baseCurrentState.IsName("Base.JumpDownRollRun") && !animator.IsInTransition(0)){
           if(useCurves){
               col.center=new Vector3(0,animator.GetFloat("ColliderY"),0);    
               col.height=animator.GetFloat("ColliderHeight");    
           }
          }
 //!!!!!!!!!
           else if(baseCurrentState.IsName("Base.Run_JumpUpHigh_Run") && !animator.IsInTransition(0)){
           if(useCurves){
               col.center=new Vector3(0,animator.GetFloat("ColliderY"),0);    
               col.height=animator.GetFloat("ColliderHeight");    
           }
          }
 //!!!!!!!!!!!
          else{
           // fallback to reset collider height & position
           col.center = new Vector3(0,1,0);
           col.height=2;
          } 
  
          // Check other moves layer for status
          if(otherMovesCurrentState.IsName("OtherMoves.Wave")){
               animator.SetBool("Wave", false );
          }    
        }     
     }   
  
     void OnAnimatorIK(){   
        if(baseCurrentState.IsName("Base.idleGrab") || baseNextState.IsName("Base.idleGrab")){
          float grabCurve = animator.GetFloat ("GrabCurve");
          AvatarIKGoal rightHand = AvatarIKGoal.RightHand;
  
          if(grabbableObj != null && !gotWrench) {
           if(useCurves){
               // Use the Curve from grabbing animation to drive smoothing of avatar hand position
               animator.SetIKPositionWeight(rightHand, grabCurve);
               animator.SetIKRotationWeight(rightHand, grabCurve);
           }
           // Set IK hand position and rotation destination 
           animator.SetIKPosition(rightHand, grabbableObj.position);
           animator.SetIKRotation(rightHand, grabbableObj.rotation);   
          }
          else{
           // Reset Hand to be controlled by animation
           animator.SetIKPositionWeight(rightHand, 0);
           animator.SetIKRotationWeight(rightHand, 0); 
          }
        }
     }
  
     void OnAnimatorMove(){
        // Set up for a rigidbody - set the RB position equal to the animator deltaPosition and increase by MoveSpeed
        rigidbody.position += animator.deltaPosition * MoveSpeed;
        transform.rotation *= animator.deltaRotation;     
     }
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by pjezek · Jun 13, 2013 at 09:32 PM

Just came from a search here. Don't know if it helps, but this is what helped me: I had to enable "IK Pass" on the layer on the Animator to pass the "if (useCurves)" block.

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

10 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

Related Questions

Edit Mecanim curves through scripts 0 Answers

Moving Object's Collider High during Animation 0 Answers

How to get accurate values from curves using Mecanim 0 Answers

Curves in Mecanim broken with Unity 4.3? 0 Answers

How to Copy mecanim curve? 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