Log inGet started
World

Fruit Fly

Branchmain
Branchesmain
Commit83f1b94a81

README.md

flyBody

A fruit fly's body as an entity tree, and a pose for it. build stands one under a root entity; update moves the root and poses every part from a motor command.

The body is a thorax, a head with two compound eyes and a pair of antennae reaching forward and down, a banded abdomen, a proboscis that extends to feed, six legs of two segments each walking a tripod gait, and two wings that lie back over the abdomen at rest and swing out to beat.

local FlyBody = require("~.flyBody")
local body = FlyBody.build(public.entity, { length = 0.6 })
body.groundY = 0
body.maxRadius = 12          -- the body cannot be moved past this radius
body:update(dt, { speed = 0.3, turn = 0.2, proboscis = 0, flight = 0 })

The motor command is { speed, turn, proboscis, flight, jump, land }: speed in world units per second along the fly's facing, turn in radians per second (positive turns left), proboscis and flight 0 to 1, jump to hop, land to put the body down. Flight lifts the body only while it is already off the ground, so a beating wing on the floor is a beating wing and the legs keep walking under it.

Readings: eye() returns the head's world position and the facing direction; mouthPosition() the proboscis tip; rightFrontFoot(), leftFrontFoot() and frontFeet() where the front feet touch; heading() the yaw.

destroy() takes down only the entities this body built, so anything else parented to the same root is left standing.

The wing and eye materials are fruitFly.wing (a thin, mostly clear membrane) and fruitFly.eye (smooth enough to hold a highlight).