iri

Path all points animation

Recommended Posts

Hi) I use this example https://www.babylonjs-playground.com/#72C7CT#3. But in this example we have all trajectory in first step. 

I tried to change this example for my  question: https://www.babylonjs-playground.com/#X0MDYG. In this example I see animation of the last segment of my all path. How can I change this situation and see animation from my first point to the last. This situation occurs when we initially do not know the entire trajectory. We only know the current and previous trajectory node.

Could anybody help me?

Share this post


Link to post
Share on other sites

The way the playground is currently set up, each call to 'heartFlight' will replace the previous animation and thus you only have the last animation.

I've fixed it with the following playground, but I don't know if that's what you are trying to do since I removed the while loop.

https://www.babylonjs-playground.com/#X0MDYG#1

Are you perhaps trying to trace a path while points are being added? If so, using animations may not be the right approach.

Share this post


Link to post
Share on other sites
12 hours ago, bghgary said:

Are you perhaps trying to trace a path while points are being added? If so, using animations may not be the right approach.

Yes, you are right. Points are added to my path. And I want animate some moving from the one point to another...

Share this post


Link to post
Share on other sites

Animations are intended to have a static set of keys. You might be able to create a queue of animations and then play them back to back as you add points to your path, but I'm not very sure if that's is any easier than just moving the object manually.

Share this post


Link to post
Share on other sites

You can also add onAnimationEnd param:

scene.beginAnimation(vehicle, 0, length, false, 10, () => {
  heartFlight(vehicle, move_trajectory, index + 1);
});

https://www.babylonjs-playground.com/#X0MDYG#2
If you added any points during the animation, they would get added to the end.  You would need code to restart a completed animation or perhaps a queue push/pop as @bghgary suggests.

I added some smoothing, so the speed is consistent on different length path segments.  If you don't want a steady speed then you can look at slerp on total length or rebuilding animation when points are added (start at current pos) and using the built-in easing functions.  cheers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.