Jump to content

Predict animation value after X frames


Hersir
 Share

Recommended Posts

Hi, 

I have rotating platform and target on it that rotates together with it. Also there is player that has jump animation, so I want to calculate when I need to jump to land on target. 

I created naive implementation in this PG. It works fine if FPS is above animation FPS (25), but I as soon FPS drops player starts to miss target. (Added function to generate  knots and added performance CPU throttle on chrome 20x); Probably because interpolation that I need to include un calculation.

Is it even possible to predict where will be target after jump animation is completed?

Any suggestions are welcome :)

Link to comment
Share on other sites

I guess you just need to adapt to animation ratio with scene.getAnimationRatio (http://doc.babylonjs.com/classes/2.5/scene#getanimationratio-rarr-number)

It will give you the scale to apply to animation to align to expected framerate.

 

For instance if you run at 15fps and animation expect to run at 30fps then the ratio will be 2 :)

Link to comment
Share on other sites

Not sure whether this was the problem or not but if last frame is 360 that makes 361 frames, and last frame 20 makes 21 frames, so decreased last frame by 1.

This PG I changed to set animation frame rate at start so you can make it larger than render frame rate and it still seems to work. Changed so variable for no other reason than I had started to set them as globals at top and then realised you had them in the WillLandOnTarget function so no good reason really.

http://www.babylonjs-playground.com/#GCSXQ5#9

Hope this helps, by the way have tried 525 as animation frame rate and it just lands on edge of target.

Link to comment
Share on other sites

@JohnK Thanks for input. But if I comment in function to generate 1000 knots and add CPU throttling (20x slowdown) on chrome it lands in opposite corner :D I am doing something wrong, as looks like that offset is related to difference between animation FPS and real FPS, the bigger the difference more off it gets.

Link to comment
Share on other sites

Oh boy I am stupid... Added shadow objects to see if calculations are correct PG, and looks like they are correct, but because of low frame rate, platform will jump over lot of frames and never will be at calculated position. Thats the reason why with lower frame rate gap is getting bigger and bigger. Will need to think how to overcome this problem,

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...