feat: let rockets plunge into the black hole core

Inside the shadow a rocket's velocity now turns toward the centre, so it falls to the
singularity instead of swinging round it, and the trail of a rocket that reaches the
core lingers and fades briefly.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 15:56:08 +07:00
parent 45497c0993
commit 88d3fa665b
3 changed files with 59 additions and 8 deletions

View File

@@ -10,8 +10,12 @@ import { ORBIT_TILT } from "./galaxyLayout.ts";
import { ambientSpring, gentleSpring, uiSpring } from "./motion.ts";
import type { ActivityEvent, FailureCause, Intent } from "./orbitActivity.ts";
/** Screen radius of the shadow, in scene units. A rocket is gone by the time it reaches it. */
/** Screen radius of the shadow, in scene units. A rocket's light is gone by the time it reaches it. */
export const SHADOW_EDGE = 34;
/** A rocket keeps falling through the shadow until it reaches the singularity at the centre, within this radius. */
export const CORE_RADIUS = 2;
/** How long the trail of a rocket that has reached the centre lingers and fades, in seconds. */
export const ABSORB_LINGER = 0.3;
/** Screen radius where gravitational redshift and tidal stretching begin to show. */
export const FADE_START = 80;
/** Strength of the black hole's pull, in scene units cubed per second squared. */
@@ -241,9 +245,20 @@ const MOMENTUM_FRACTION = 0.97;
/** The longest a rocket waits for a good launch window: about one lap of its circle. */
const MAX_WAIT = 3;
const FAILING_CUT = 0.55;
/** How fast velocity turns toward the centre once inside the shadow, per second. */
const PLUNGE_RATE = 40;
const FALL_STIFFNESS = 90;
const FALL_DAMPING = 8;
/** Whether a straight move of (dx, dy) from (x, y) comes within the core radius of the centre, measured on the screen. */
function passesCore(x: number, y: number, dx: number, dy: number) {
const sy = y * ORBIT_TILT;
const dsy = dy * ORBIT_TILT;
const length2 = dx * dx + dsy * dsy;
const t = length2 > 1e-12 ? Math.min(1, Math.max(0, -(x * dx + sy * dsy) / length2)) : 0;
return Math.hypot(x + dx * t, sy + dsy * t) <= CORE_RADIUS;
}
function stepLaunch(rocket: Rocket, dt: number) {
const steps = Math.max(1, Math.ceil(dt / SUBSTEP));
const h = dt / steps;
@@ -274,9 +289,30 @@ function stepLaunch(rocket: Rocket, dt: number) {
rocket.vx += ax * h;
rocket.vy += ay * h;
// Inside the shadow every path leads to the centre: the velocity turns inward at the same speed, so the rocket
// plunges straight to the singularity instead of swinging round it and coming back out.
if (Math.hypot(rocket.x, rocket.y * ORBIT_TILT) < SHADOW_EDGE && rr > 1e-6 && !rocket.failing) {
const speed = Math.hypot(rocket.vx, rocket.vy);
// Faster rockets cross more ground per step, so they turn in proportionally harder and cannot sling past the centre.
const blend = 1 - Math.exp(-PLUNGE_RATE * Math.max(1, speed / 300) * h);
const tx = rocket.vx + (-(rocket.x / rr) * speed - rocket.vx) * blend;
const ty = rocket.vy + (-(rocket.y / rr) * speed - rocket.vy) * blend;
const turned = Math.hypot(tx, ty) || 1;
rocket.vx = (tx / turned) * speed;
rocket.vy = (ty / turned) * speed;
}
// Whether this step carries the rocket through the core: it moves several units a step, so it can cross the centre
// between two checks.
const reaches = !rocket.failing && passesCore(rocket.x, rocket.y, rocket.vx * h, rocket.vy * h);
rocket.x += rocket.vx * h;
rocket.y += rocket.vy * h;
rocket.modeAge += h;
// Reaching the centre ends the flight exactly there, so the trail finishes at the singularity.
if (reaches) {
rocket.x = 0;
rocket.y = 0;
break;
}
}
stepSpring(rocket.thrust, rocket.failing && rocket.modeAge > FAILING_CUT ? 0 : rocket.modeAge < LAUNCH_BURN ? 1 : 0.25, uiSpring, dt);
stepSpring(rocket.alpha, 1, gentleSpring, dt);
@@ -303,8 +339,9 @@ export function stepRocket(rocket: Rocket, star: StarPose, dt: number): FieldEve
if (rocket.mode === "launch") {
stepLaunch(rocket, dt);
if (rocket.failing && rocket.modeAge > FAILING_CUT) setMode(rocket, "fall", star);
else if (screenRadius(rocket.x, rocket.y) <= SHADOW_EDGE) {
else if (screenRadius(rocket.x, rocket.y) <= CORE_RADIUS) {
rocket.mode = "gone";
rocket.modeAge = 0;
rocket.arrived = true;
return { kind: "arrive", id: rocket.id };
}
@@ -453,6 +490,12 @@ export function stepField(field: Field, dt: number, starOf: (id: string) => Star
field.rockets.delete(id);
continue;
}
// A rocket that reached the centre stays a moment so its trail can be drawn to the singularity and fade there.
if (rocket.mode === "gone" && rocket.arrived) {
rocket.modeAge += dt;
if (rocket.modeAge > ABSORB_LINGER) field.rockets.delete(id);
continue;
}
const event = stepRocket(rocket, star, dt);
if (rocket.mode === "launch") feeding = Math.max(feeding, smoothstep(140, SHADOW_EDGE, screenRadius(rocket.x, rocket.y)));
if (event) {
@@ -464,7 +507,7 @@ export function stepField(field: Field, dt: number, starOf: (id: string) => Star
pulse(field, id);
out.push({ kind: "boom", id });
}
field.rockets.delete(id);
if (event.kind !== "arrive") field.rockets.delete(id);
}
}