Something went wrong. Try again.
Starship Simulator Controls thoriumsim.com
Something went wrong. Try again.
1.2 kB · 27 lines
TypeScript
at develop
12345678910111213141516171819202122232425262728import { type Entity, System } from "@thorium/utils/ecs";
const constant = 5000000;export class RandomMovementSystem extends System { static flightMode = ["nova"]; test(entity: Entity) { return !!(entity.components.position && entity.components.velocity); } update(entity: Entity, elapsed: number) { const elapsedRatio = elapsed / 1000; if (!entity.components.velocity) return; if (!entity.components.position) return; const xSign = entity.components.position.x > 0 ? -1 : 1; const ySign = entity.components.position.y > 0 ? -1 : 1; const zSign = entity.components.position.z > 0 ? -1 : 1; const accelerationX = Math.random() * xSign * constant; const accelerationY = Math.random() * ySign * constant; const accelerationZ = Math.random() * zSign * constant; entity.components.velocity.x += accelerationX; entity.components.velocity.y += accelerationY; entity.components.velocity.z += accelerationZ;
entity.components.position.x += entity.components.velocity.x * elapsedRatio; entity.components.position.y += entity.components.velocity.y * elapsedRatio; entity.components.position.z += entity.components.velocity.z * elapsedRatio; }}