Jump to content

Change speed ratio of loop animation


Hersir
 Share

Recommended Posts

Hi,

I have object thats need to rotate around y forever, but sometimes I need to play that animation slower (from current point). I created Playground, to change speed ratio by click on canvas. Is that correct approach or is there better solutions for that?

And after I regenerate animation on click, it jumps on frame where full circle ends (360 to 0). Looks like it moves around full circle quickly and than continue as usual. That happens if start angle of mesh is not 0.

Thanx.

Link to comment
Share on other sites

@aWeirdo Hi.

Yes I tried that but I need frame rate independent animation as this rotation animation needs to be in sync with other more complex animations (can I somehow sync registerBeforeRender with frame rate?  ). :) So idea is to slow down both animations so that their positions matches in both slow down and normal mode. Just they are played slower or in normal rate.

Link to comment
Share on other sites

@Hersir your way is what I would have done, it gives you control over the animation and you can extend it as needed.

As @aWeirdo said, the alternative would be to work on the registerBeforeRender but I personally prefer to have stuff placed into their own section (e.g. animation stuff within the animation callback). But that works as well :) 

Link to comment
Share on other sites

Hi,

I'm not sure i understand, Everything is dependant on the frame rate, both registerBeforeRender and animations update once per frame.

 

anyway, as @Nesh108 mentioned, animations does give some nice built-in control :-) 

the "jump" is no doubt fixable if that is the main issue, i've got to run now, but will check up on it later if nobody else beats me to it.

Link to comment
Share on other sites

If animation should finish in 2 sec, than it will finish in 2 sec on both 60fps or 10fps. RegisterBeforeRender will be triggered differently on different fps so manual delta time should be added. I am just thinking about performance will creating and recreating the animation kill performance. 

 

Now I will try to fix the jump, as it works ok if start angle is 0, but jumps if start angle is different.

Link to comment
Share on other sites

3 hours ago, aWeirdo said:

I'm not sure i understand, Everything is dependant on the frame rate, both registerBeforeRender and animations update once per frame.

There is a difference between animation frame rate and rendering frame rate because they are talking about different frames.

The rendering frame rate is the speed that a sequence of scenes is drawn. Consider an animation as a series of images (albeit in this case the images are drawn by the BJS engine). The animation frame rate is the speed that a sequences of images are drawn.

Suppose we set an animation speed to be 20 animation frames per second and the rendering speed is 60 rendered frames per second.

In the first 1/20 of a second the first animation frame is displayed but the scene has been rendered 3 times even though the scene image does not change ( expect by camera movement)

So taking your example and thinking about using registerBeforeRender, you want your object to rotate at R radians/second and the rendering speed at any time is F frames/second.

During the rendering loop you can get the rendering speed using F = engine.getFps();

So the time taken for one rendering loop is 1/F seconds and thus the angle rotated by the object during that time will be R/F radians

This way if the animation should finish in 2 sec, than it will finish in 2 sec on both 60fps or 10fps.

http://www.babylonjs-playground.com/#WCY578#17

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...