Making games
Characters, cars and sound
The player character
character.lua is a complete third-person player on a rigged model:
| Input | |
|---|---|
| WASD / left stick | walk, relative to the camera |
| Shift / left trigger | sprint |
| Space / A | jump (with a short grace period after walking off a ledge) |
| Mouse / right stick | orbit the camera |
| Left mouse | kick the prop in front of you |
| F | get into / out of a nearby car |
It turns to face where it moves, plays idle / walk / sprint / jump / fall animations, plays footsteps that match the ground and a sound on landing, and pulls the camera in when a wall is in the way. Easy mode's Player button and the Coin Collector, Sumo Arena and Town Roleplay templates use it.
Tune it with Script Fields: walk_speed, sprint_speed, jump_speed, air_control, turn_speed,
mouse_sensitivity, cam_distance, cam_height, stride, kick.
Skeletal animation
Rigged glTF models play their own clips. Add Skeletal Animation (or just call play_animation on the
object) and switch clips from scripts; changes crossfade smoothly:
self.entity:play_animation("walk", true, 1.2) -- clip, loop, speed
print(table.concat(self.entity:animations(), ", "))
The bundled character (models/kenney/arena/character-soldier.glb, CC0) has idle, walk, sprint, jump,
fall, drive, die, emotes and more. Animation is skinned on the CPU, which is fine for a handful of
characters but not for crowds. There's no animation state machine, IK or root motion: scripts pick the clip.
Keyframe animation
View > Animation opens a timeline for the selected object. Press Record and move things to make
keys. Clips (.anim) can animate position, rotation, scale, tint, emissive, visibility, light intensity,
light colour, camera field of view and audio volume, with eight easings (linear, step, ease in, ease out,
ease in-out, bounce, elastic, back). Event keys call on_animation_event(name). Relative clips play on
any object, so one "bob" clip can serve every coin.
self.entity:play_animation("anims/door_open.anim")
Cars
car.lua turns a model with a dynamic box collider (Lock rotation on) into an arcade car. Give it an Audio
Source with sounds/car_engine.ogg (loop, play on start) for the engine. The Stunt Drive, Time Trial and
Town Roleplay templates have ready-made cars.
- W / S throttle and brake / reverse, A / D steer, Space handbrake, H horn, R repair.
- The engine sound revs through the gears (its pitch follows the speed), tyres squeal when sliding and crashes thump.
needs_driver = truein Script Fields makes it wait for the player to get in with F.model_yaw = 180flips a model that was built facing backwards (Kenney vehicles are detected automatically).- Tune it with
accel,max_speed,reverse,steer,gripanddrag.
Crash deformation
Add Component > Crash Deformation (dents): hard hits push the model's vertices in around the contact
point. Settings: softness, maximum dent depth, dent radius and the minimum impact speed. Scripts read
entity.damage (0..1), dent by hand with entity:dent(point, direction, speed) and fix it with
entity:repair().
This deforms the object's own copy of its mesh. It isn't a node-and-beam soft-body simulation like BeamNG's: there's no tearing, nothing falls off, and the collision shape doesn't change.
Sound
- Audio Source component: a clip (WAV, OGG, MP3, FLAC) with volume, pitch, loop, play on start and 3D falloff between a min and max distance. Looping sounds are streamed.
- One-shots from scripts:
audio.play("sounds/coin.wav", position, volume, pitch). - Live changes:
entity.sound_volumeandentity.sound_pitchcan be set every frame (engine revs, fades, wind gusts). - Footsteps (
footsteps.lua): the surface underfoot (terrain layer, the texture or name of the object, water) picks grass, dirt, stone, sand, snow, wood, metal or water steps, three variations each. - Ambience (
ambience.lua): every template plays a looping ambience for its world (forest birds, ocean, wind, desert, night crickets, cave drips, lava rumble, city, rain) with gentle gusts. audio.tone{…}makes retro beeps without any sound file.
All bundled sounds are CC0: Kenney's starter kits, plus ambience and footsteps synthesised by Ember's own generator.