gizgame/ball
Universal sports ball physics, parabolic shot solver, and goal-volume scoring.
import * as Ball from "gizgame/ball";Types
Ball
type Ball = { pos: Point3; vel: Point3; rot: f64; radius: f64; bounced: bool; }Physical state of a sports ball.
pos:gizlang_geometry.Point3vel:gizlang_geometry.Point3rot:f64radius:f64bounced:bool
BallConfig
type BallConfig = { gravity: f64; bounce: f64; drag: f64; floorY: f64; maxX: f64; maxZ: f64; wallBounce: f64; }Arena physics parameters for a ball.
gravity:f64bounce:f64drag:f64floorY:f64maxX:f64maxZ:f64wallBounce:f64
GoalBox
type GoalBox = { name: string; minX: f64; maxX: f64; minY: f64; maxY: f64; minZ: f64; maxZ: f64; }Axis-aligned goal or hoop scoring volume.
name:stringminX:f64maxX:f64minY:f64maxY:f64minZ:f64maxZ:f64
Functions
makeBall
function makeBall(pos: Point3, radius: f64 = 0.35): BallA ball of RADIUS at rest at POS.
stepBall
function stepBall(b: Ball, cfg: BallConfig, dt: f64): BallSteps a ball under gravity, ground restitution, linear drag, and field bounds.
Effects: fail.
kickBall
function kickBall(b: Ball, dirX: f64, dirZ: f64, power: f64, lift: f64): BallApplies a directional impulse kick or strike to a ball.
shootArc
function shootArc(origin: Point3, target: Point3, gravity: f64, flightSeconds: f64): Point3Solves an initial velocity that arcs a ball from origin to target with a given flight time.
inGoal
function inGoal(b: Ball, g: GoalBox): boolChecks whether the ball center lies inside a goal volume.
checkGoals
function checkGoals(b: Ball, goals: Vec<GoalBox>): stringReturns the name of the first goal volume the ball entered, or empty string if none.
Effects: fail.