gravity

package
v0.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 24 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gravity has bodies fall, stand on what bears them and leap: a character's controller, never rigid bodies.

Pull and Body

NewPlugin gives the world its gravity, a Pull on the plugin's own entity: a knob an effect's Alter turns. A kind falls carrying a Body, which says how high it leaps; the plugin gives it a motion.Drift, the velocity motion carries it at beyond its walk. Whatever carries a Body is a unit of the board: unit.Airborne is on while it is in the air.

Two modes

The pull's way is the mode, kept as long as the world lasts. Along Z (a world with heights) every step a body stands on the surface under its centre (Plugin.WithSurfaces, the board's ground.Surfaces), follows the ground down a slope within its reach, flies off a deck's edge, by a leap or a throw, and lands. Across X and Y (a platformer's side view, its Z the depth) a body is borne by whatever collision found it touching against the pull, a wall bearing nothing. Along Z a body falls slowing with its distance in levels from the finest any observer sees (lod.Slowing), across every step within two levels of it (lod.Contact), where collision runs.

Commands and Landing

Leap and Away are an entity's own (act.Self.Do, driving.Jump): a leap throws a standing body up to its Body's height, an Away throws it off across and up, away from the subject of the moment it is given on. A Landing is told the rules the plugin hosts once as a body lands, with how fast it fell (HarderThan). Run the plugin's RunPlan right after collision's.

Vocabulary

Moments, for a role's rules: Landing (once as a body lands; its word HarderThan). Knobs, for an effect's Alter: Pull (on the plugin's own entity). Commands, an entity's own: Leap, Away (aimed at the moment's subject, host.Aimed).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HarderThan

func HarderThan(speed float32) cond.Word[Landing]

HarderThan is the word of a body come down faster than speed (world units a second).

Types

type Away

type Away struct {
	Speed float32
	Rise  float32
	// contains filtered or unexported fields
}

Away is the command an entity gives itself to be thrown off at Speed across, rising Rise high first. It is host.Aimed: thrown away from the subject of the moment it is given on, else back from the way it faces.

func (*Away) Aim

func (a *Away) Aim(who uid.UID64)

Aim tells the command whom to be thrown away from.

func (Away) Command

func (Away) Command()

type Body

type Body struct{ Leap float32 }

Body makes an entity fall under the Pull, stand on what bears it and leap; Leap is how high it leaps, in world units (0, not at all). Its drift and, with heights, its altitude are written by gravity alone.

type Config

type Config struct {
	// Pull is the pull the world begins under, along Z or across X and Y; zero, the Earth's as its
	// figures feel it: −Z in a world with heights, +Y (down the screen) in a flat one.
	Pull Pull
}

Config is how a world's gravity begins.

type Landing

type Landing struct {
	ID    uid.UID64
	Speed float32
}

Landing is a body coming down on what bears it, told once as it lands; Speed is how fast it fell, in world units a second.

func (Landing) Who

func (l Landing) Who() uid.UID64

Who is the body landing.

type Leap

type Leap struct{}

Leap is the command an entity gives itself to leap as high as its Body says; one in the air does not.

func (Leap) Command

func (Leap) Command()

type Plugin

type Plugin struct {
	*world.Self
	// contains filtered or unexported fields
}

Plugin is gravity over the entities of a world that carry a Body: every step it carries each by its drift, stands it on what bears it, lets it fall and lands it, a Landing for the rules it hosts.

func NewPlugin

func NewPlugin(w *world.Plugin, m *motion.Plugin, cfg Config) *Plugin

NewPlugin builds the gravity of w as cfg begins it, m carrying what it drifts: along Z, a body falling to the ground, or across X and Y, a side view's. A pull both ways, or along Z in a flat world, panics.

func (*Plugin) DefaultBindings

func (p *Plugin) DefaultBindings() []control.Binding

DefaultBindings are none: a key leaps through driving.Jump.

func (*Plugin) EventHandler

func (p *Plugin) EventHandler() control.EventHandler

EventHandler is nil: gravity reads no input.

func (*Plugin) Install

func (p *Plugin) Install(ctx plugin.Installer) error

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) Queues

func (p *Plugin) Queues() []command.CommandQueue

Queues are where Leap and Away land.

func (*Plugin) RunPlan

func (p *Plugin) RunPlan(ctx goke.RunCtx, d time.Duration)

RunPlan runs the fall in the simulation; call it right after collision's.

func (*Plugin) Serializable

func (p *Plugin) Serializable() plugin.Serializable

Serializable is nil: the pull and the drifts are on the entities.

func (*Plugin) WithSurfaces

func (p *Plugin) WithSurfaces(surfaces func() ground.Surfaces) *Plugin

WithSurfaces gives the plugin what bears a body falling along Z (the board's Footing); without it the ground lies at 0. A pull across panics; call before Use.

type Pull

type Pull struct{ X, Y, Z float32 }

Pull is the gravity of a world, a knob on the plugin's own entity in world units a second squared: along Z, or any way across X and Y, never turned from the one to the other. The plugin only reads it, so an effect's Alter turns it.

func (Pull) Knob

func (Pull) Knob()

Knob: an effect may turn it (effect.Knob).

Directories

Path Synopsis
internal
planar
Package planar is a body's fall across the plane, a platformer's: the pull any way across it, the body borne by whatever collision found it touching against the pull.
Package planar is a body's fall across the plane, a platformer's: the pull any way across it, the body borne by whatever collision found it touching against the pull.
vertical
Package vertical is a body's fall along Z: a step of the pull along the vertical between the surface under its feet and the slab over its head.
Package vertical is a body's fall along Z: a step of the pull along the vertical between the surface under its feet and the slab over its head.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL