Getting Started - Chapter 3 - Car Animation
Animate the Car in the Village
In a similar way to how we animated the wheels, we now animate the car so that it travels in a straight line over 5 seconds, stops for 2 seconds, and then repeats.
import { Animation } from "@babylonjs/core/Animations/animation";const animCar = new Animation("carAnimation", "position.x", 30, Animation.ANIMATIONTYPE_FLOAT, Animation.ANIMATIONLOOPMODE_CYCLE);const carKeys = [];carKeys.push({ frame: 0, value: -4});carKeys.push({ frame: 150, value: 4});carKeys.push({ frame: 210, value: 4});animCar.setKeys(carKeys);car.animations = [];car.animations.push(animCar);scene.beginAnimation(car, 0, 210, true);After adjusting the position of the car and its route so that it travels past the village houses, we have:
Add the Car to the VillageIn this case, we built the car ourselves. Let's now look at a model character that we can import along with its built-in animation.