- Home /
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;
}
}
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.
Your answer
Follow this Question
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