- Home /
script Animation issues
Hello again!
I am trying my hand at some animations.
I have created a very simple door in blender animated it and imported it into unity.
Inside the .fbx there was one animation, just the door sliding to the side.
I first created a new Animator controller, in the animator tab I dragged the animation from the .fbx into the window to create a new State I think they are called.
The animation was on auto play somewhere so I read online that I need to create another state. So I did I created an empty state with the default name.
I added a bool to the animator of true and false, and called it open. after I made the new state the default and added a transition from the new state to the animated state.
It was no longer auto playing so that was good!
I started to write a script in c#
Animator anim;
void Start () {
anim = GetComponent<Animator>();
}
void OnCollisionEnter (Collision col) {
if(col.transform.tag == "player") {
anim.SetBool ("open", true);
}
}
I thought this would make it so when the player walked into the collider of the door then the bool of open would be set to true and the door would play the animation, it did nothing. So I played around with the animator a little.
So I set the conditions of the transition from New State to Cube|CubeAction to be set to
open and true and the Cube|CubeAction to open and false
But it still does not work, so after a few youtube videos and many form posts I have come (yet again) here for help!
SOrry for this being so long, I thought the more information I provided the better!
Thanks for the help
First things first - does your OnCollisionEnter() method get called at all? Put a Debug.Log('Got Here!'); before the anim.SetBool() line - does it print anything in the console?
Also, doors are typically opened by triggers rather than colliders - do you have the collider marked as IsTrigger?
Yes, OnCollisionEnter is being called, I used print("Hit") and it worked.
The door is not set to trigger either, making it a trigger just makes it so my player can walk into the collider.
O$$anonymous$$ so using what you said, I took another look at it, and set false to true and true to false, set it to a trigger, and changed it to OnTriggerEnter and then it worked.
i don't think I would of been able to get there without reading what you said so Thank you for your help!
"I added a bool to the animator of true and false, and called it open. after I made the new state the default and added a transition from the new state to the animated state" did you properly added the transition from one state to the other to be according to the bool value?