Jan-Bart Posted June 20, 2018 Share Posted June 20, 2018 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! Quote Link to comment Share on other sites More sharing options...
Sebavan Posted June 20, 2018 Share Posted June 20, 2018 @JohnK will be pretty happy to help knowing you are reading his great tutorials serie ? Jan-Bart 1 Quote Link to comment Share on other sites More sharing options...
JohnK Posted June 20, 2018 Share Posted June 20, 2018 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. Quote Link to comment Share on other sites More sharing options...
Jan-Bart Posted June 20, 2018 Author Share Posted June 20, 2018 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 Quote Link to comment Share on other sites More sharing options...
JohnK Posted June 20, 2018 Share Posted June 20, 2018 @Jan-Bart apologies forgot to post tweaked PG http://www.babylonjs-playground.com/#1YD970#45 Quote Link to comment Share on other sites More sharing options...
JohnK Posted June 20, 2018 Share Posted June 20, 2018 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 } Jan-Bart 1 Quote Link to comment Share on other sites More sharing options...
Jan-Bart Posted June 20, 2018 Author Share Posted June 20, 2018 That's exactly what I was looking for. Thanks @JohnK! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.