Feedback Animstategraph: Reverse animation even when finished

I don’t need help as I can achieve my goals with a walkaround, but I wanted to share this. Tomorrow I’ll take a look at anim-controller.js anyway.

Simple example:

We have a door that opens when we get close to it.

By manipulating the anim.speed parameter, we can control the speed it opens with the distance. The closer we are, the faster it opens.

With the same parameter, when we get far enough, speed becomes negative, and the door starts closing.

So far so good.

Problem is, if it opens completely (animation finishes), then even when we set up the speed negative, it doesn’t close.

4 things I’ve noticed:

  1. If we close it before it opens completely, we can open it again
  2. When it opens completely and it gets stuck, it still shows as being still in that activeState
  3. Even when stuck, _controller._timeInState is responsive, but the animation just ignores it
  4. If we close the door for too long, later the door will take a long time to open again (until _controller._timeInState > 0). I don’t think this was intended.

Function reset restarts the full graph, so it’s not the best solution
We can play with _controller.play , but is not clean
You can achieve similar results with more complex graphs.

1 Like

I’ll not have time to go deep into the source code until the end of the next week, but today I played a little.

I attached a script to the animation that basically checks if the next frame will be in the range [0, last_frame]. If it’s not, it sets speed = 0

It works perfectly, let’s see if we can achieve this natively.

Do you have an example project that showcases the issue you ran into?

I’ll prepare one

1 Like

Here you have:

https://playcanvas.com/editor/scene/1461947

The blue door is inside a loop with 2 animations, open and close.

The green one has speed control, and its range is also limited, so you can control it and it will not get stuck.

The red one has speed control, but its range is not limited, therefore it will get stuck and will also delay its opening.

1 Like

How do you trigger the red and green doors?

By distance door-camera

The script has a few parameters:
* Player = camera
* range
min_range => speed = 1
max_range => speed = 0
(calculated inside) min_range + 2* max_range => speed = -1
* verbose = some messages in the console

Ahh, interesting. I see what you mean now that activeStateCurrentTime isn’t capped at 0/duration. I raise it with Elliott in a ticket and see what he thinks

Created ticket about this: https://github.com/playcanvas/engine/issues/4404