# Animation backwards, ElapsedTime returns strange value

**URL:** https://forum.castle-engine.io/t/animation-backwards-elapsedtime-returns-strange-value/2069
**Category:** Bugs
**Created:** [December 24, 2025, 10:32am UTC](https://forum.castle-engine.io/t/animation-backwards-elapsedtime-returns-strange-value/2069 "2025-12-24T10:32:43Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![BlueIcaro](https://forum.castle-engine.io/letter_avatar_proxy/v4/letter/b/eada6e/32.png) [@BlueIcaro](https://forum.castle-engine.io/u/BlueIcaro)
#### Post date: [December 24, 2025, 10:32am UTC](https://forum.castle-engine.io/t/animation-backwards-elapsedtime-returns-strange-value/2069/1 "2025-12-24T10:32:43Z")

</div>

I am playing an animation forward and backward. To determine the current position of the animation, I use `ElapsedTimeInCycle`, as I need to move the sprite based on the current frame.

I wrote, because I don’t know how to get the current frame

ElapseTime := TCastleScene(Parent).CurrentAnimation.ElapsedTimeInCycle;

if ElapseTime \< 1.3 then  
begin  
TCastleScene(Parent).Translation := FPosicionActual + Vector3(0, -15, 0);  
end  
else if (ElapseTime \> 1.3) and (ElapseTime \< 1.8) then  
begin  
TCastleScene(Parent).Translation := FPosicionActual + Vector3(0, -5, 0);  
end  
else  
begin  
TCastleScene(Parent).Translation := FPosicionActual;  
end;

This works when the animation runs forwards, but when goes backwards, the first value is 2.60, and the next value is 0.1, 0.2.., 2.30 as I can see in the log.

 ![image](https://forum.castle-engine.io/uploads/default/original/2X/8/87ee5adb4d4d44aa8c3f10724c16f0f413d49c0c.png)

 ![image](https://forum.castle-engine.io/uploads/default/original/2X/7/742e6ce21e60bd43e640ce027a1c0a57ca77c770.png)

Is this a bug?, For workaround I wrote

if ElapseTime \> 2.30 then  
begin  
Exit;  
end;

Is there any way to know which frame is running?.

Thanks

/BlueIcaro

---

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [December 24, 2025, 12:28pm UTC](https://forum.castle-engine.io/t/animation-backwards-elapsedtime-returns-strange-value/2069/2 "2025-12-24T12:28:15Z")

</div>

The way playing animation backward works (e.g. when you set `TPlayAnimationParameters.Forward=false`) is that most of the animation parameters (including `ElapsedTimeInCycle`) still move “forward”, but instead of “fraction in animation” (in 0..1 range) we send “1.0 - fraction in animation” to the interpolator nodes.

Basically, to know “frame in animation” and account for this, you need to do sthg like

```auto
AnimationNode := TCastleScene(Parent).CurrentAnimation;
if AnimationNode = nil then
  Exit; // not playing any animation now
if AnimationNode.FractionIncreasing then // FractionIncreasing corresponds to TPlayAnimationParameters.Forward
  Time := AnimationNode.ElapsedTimeInCycle
else
  Time := AnimationNode.CycleInterval - AnimationNode.ElapsedTimeInCycle;
...
// and then your code can follow, treating Time to indicate point in animation

```

This can be confirmed e.g. by our [Castle Model Viewer](https://castle-engine.io/castle-model-viewer), it shows `CurrentAnimation.ElapsedTimeInCycle` when it plays ( [castle-model-viewer/code/v3dscenenamedanimations.pas at 229794ff9527f3a2fb32c6e4e6afc28314395c9c · castle-engine/castle-model-viewer · GitHub](https://github.com/castle-engine/castle-model-viewer/blob/229794ff9527f3a2fb32c6e4e6afc28314395c9c/code/v3dscenenamedanimations.pas#L387) ).

I’m not sure does this explain everything you observe – you observe weird values 🙂 Please let me know if this doesn’t explain all issues, and send the testcase (program code + data) to reproduce the problem, I’ll see can I help better then 🙂

---

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [December 24, 2025, 12:36pm UTC](https://forum.castle-engine.io/t/animation-backwards-elapsedtime-returns-strange-value/2069/3 "2025-12-24T12:36:44Z")

</div>

P.S. I improved our docs to document how animation playing backward and `ElapsedTimeInCycle` interact: [Document how ElapsedTimeInCycle interacts with playing animation back… · castle-engine/castle-engine@6caed57 · GitHub](https://github.com/castle-engine/castle-engine/commit/6caed57cadcdd9ff383df8028e4bb274ca17732b) .
