Jump to content

[Solved] Slow down Car on "Simple Car Following Path" Gamelet


Jan-Bart
 Share

Recommended Posts

Hi all!

I'm a newbie, so maybe this is a rather silly question, but as I was playing with the "Simple Car Following Path" gamelet on https://babylonjsguide.github.io/gamelets/Car_Path

I was wondering if it's possible to speed up (or slow down) the car without changing the framerate. (eg everything would slow down/speed up)
If it's possible, how should I do it? Or is this not the best way to animate a car on a path?

Thanks in advance!

Link to comment
Share on other sites

Hi @Jan-Bart and welcome to the forum from me. Tweaked the PG a bit. Slowed down the car by increasing the number of points along the curve (line 84) this will determine the minimum possible speed. So if you want to stop the car you would need to stop the animation. You can then increase the speed of the car by, in the animation, jumping to points further ahead (use of var speed) You could control the value of speed if you want to with key presses. Note speed has minimum value of 1 and must be an integer. More accurately k must be an integer so you could use k = Math.round(i + speed).

http://www.babylonjs-playground.com/#1YD970#45

Hope this gives you somewhere to go. 

Link to comment
Share on other sites

Hi @JohnK , thanks for answering my question and your tutorial serie, it's really helping me getting to know Babylon.
By PG you're referencing to the Playground I suppose? (yeah, newbie...) and more specificly this one? http://www.babylonjs-playground.com/indexStable.html#1YD970#14

Also; is it correct that if you stop the animation all other moving things (eg other cars) would stop at the same time?

I get what you mean by skipping points further ahead and will try this asap

Link to comment
Share on other sites

49 minutes ago, Jan-Bart said:

Also; is it correct that if you stop the animation all other moving things (eg other cars) would stop at the same time?

No. Within scene.registerAfterRender loop use an 'if' statement to move car if not stopped and keep any other animations running

scene.registerAfterRender(function()) {
    if(car not stopped) {
       move car
    }
    do other animations
}

 

Link to comment
Share on other sites

  • Jan-Bart changed the title to [Solved] Slow down Car on "Simple Car Following Path" Gamelet

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