Using animations

So I got an animated door off of sketchfab, and I have never used animations before. I looked at the page for Animation on the PlayCanvas Developer site, and I thought I did everything right, but the animation doesn’t play on loading the game.
Here is the project: PlayCanvas | HTML5 Game Engine
The object which I am trying to play an animation with is called “woodenDoor_01_v1_ANIM”

You are using the legacy Animation component which isn’t compatible with the render hierarchy workflow.

Please use the updated tutorial here: Anim State Graph Blending | Learn PlayCanvas

1 Like

Cool, that really helped.
There is an issue though-- the animation asset plays the door opening and then closing immediately after. Is there a way I can stop the animation early so that it doesn’t do this?

You can add animation event where the door is fully opened. This would allow you to write some code to pause the animation until later:

Great! One more question though-- how do I run an animation in code from another entity? I would like to run the door animation from a script attached to the player entity, so that the door opens when they press E, and I have attempted this on line 57 of objectPicker.js. This did not work, so what do I do?
Edit: Yeah, it’s giving me a typeError for “anim” when I use“woodenDoor”).entity.anim.setBoolean(open, true);
Also, I read the Anim Events page, and it’s not making a lot of sense to me. Could you explain?

As it’s all one animation rather than several, you would have one state for the animation and you would have to control that directly through playing/stopping/pausing and setting the active time on the baseLayer.

It would be a lot easier to do if you had multiple animations (open, close and idle)

Yeah, I just don’t know how to seperate the “open” and “close” parts from each other.
Edit: Wow, that baseLayer page is really confusing. There’s got to be a way to seperate these, right?
Edit 2: I created a new script called AnimEvent.js. Is this the correct way to use Anim Events? I’m just trying to get something to happen, because I’m not sure how to pause the animation (if you do, that would be a big help), so I am just setting its position way far away.

OK, I might just make two overlapped entities. One would be an open door and one would be a closed door. Then I can just disable the closed door entity and enable the open door entity.

Posted an Office Hours video on this:

Link to project: PlayCanvas 3D HTML5 Game Engine

1 Like