This commit is contained in:
33333-33333 2026-07-10 16:40:06 +09:00
commit 2636d580a8
75 changed files with 3890 additions and 1084 deletions

View file

@ -4,6 +4,7 @@
const Geometry = global.TarinaiGeometry;
function circleBounceOffOrientedRect(obj, rect, radius, restitution, worldRef, opts = {}) {
if (Geometry.oneWayFenceAllows(obj, rect)) return false;
const hitRadius = Math.max(2, Number(radius || obj.r || obj.radius || 12) || 12);
const minBounceSpeed = Math.max(0, Number(opts.minBounceSpeed ?? rect.minBounceSpeed ?? 0) || 0);
const local = Geometry.rectLocalPoint(rect, obj.x, obj.y);
@ -55,22 +56,7 @@
obj.y = (rect.cy || 0) + worldClosest.y + ny * (hitRadius + 0.5);
const vx = obj.vx || 0;
const vy = obj.vy || 0;
const toward = vx * nx + vy * ny;
if (toward < 0) {
obj.vx = vx - (1 + restitution) * toward * nx;
obj.vy = vy - (1 + restitution) * toward * ny;
} else {
obj.vx = vx + nx * 36;
obj.vy = vy + ny * 36;
}
if (minBounceSpeed > 0) {
const normalSpeed = (obj.vx || 0) * nx + (obj.vy || 0) * ny;
if (normalSpeed < minBounceSpeed) {
const add = minBounceSpeed - normalSpeed;
obj.vx = (obj.vx || 0) + nx * add;
obj.vy = (obj.vy || 0) + ny * add;
}
}
applyNormalBounce(obj, nx, ny, vx, vy, restitution, 36, minBounceSpeed, rect.mechanical ? 0 : 7.0, 46);
if (rect.mechanical) {
global.TarinaiMechanicalSystem.applySurfaceVelocityToCircle(obj, rect, nx, ny, vx, vy, {
damping: 1,
@ -80,7 +66,7 @@
passiveImpulseScale: 1.0,
spinKick: 7.0,
});
} else if (Number.isFinite(obj.spinVelocity)) obj.spinVelocity = clamp((obj.spinVelocity || 0) + (nx >= 0 ? -1 : 1) * 7.0, -46, 46);
}
return true;
}
@ -121,7 +107,7 @@
}
function bounceCircleOffRect(obj, rect, radius, restitution = 2.40, worldRef = null, opts = {}) {
function bounceCircleOffRect(obj, rect, radius, restitution = 4.20, worldRef = null, opts = {}) {
if (!obj || !rect) return false;
if (rect.oriented) return circleBounceOffOrientedRect(obj, rect, radius, restitution, worldRef, opts);
const hitRadius = Math.max(2, Number(radius || obj.r || obj.radius || 12) || 12);
@ -194,9 +180,9 @@
const rects = worldRef.nearbySolidObstacleRects(item.x, item.y, searchRadius, { include: it => it?.type === "bounce_fence" || it?.type === "bounce_fence_v", exclude: item, maxChecks: 16 }) || [];
for (const rect of rects) {
if (!rect?.bounce) continue;
if (bounceCircleOffRect(item, rect, radius, Number(rect.restitution || 2.40), worldRef, opts)) {
if (bounceCircleOffRect(item, rect, radius, Number(rect.restitution || 4.20), worldRef, opts)) {
bounced = true;
const maxSpeed = opts.bounceFenceMaxSpeed ?? 1180;
const maxSpeed = opts.bounceFenceMaxSpeed ?? 1680;
item.vx = clamp(item.vx || 0, -maxSpeed, maxSpeed);
item.vy = clamp(item.vy || 0, -maxSpeed, maxSpeed);
const now = worldRef.time || 0;
@ -247,5 +233,14 @@
return speed;
}
global.TarinaiPhysics = { bounceCircleOffRect, applyKinematicItemMotion };
global.TarinaiPhysics = {
oneWayFenceAllowsMotion(...args) {
return global.TarinaiGeometry.oneWayFenceAllowsMotion(...args);
},
oneWayFenceAllows(...args) {
return global.TarinaiGeometry.oneWayFenceAllows(...args);
},
bounceCircleOffRect,
applyKinematicItemMotion,
};
})(typeof window !== "undefined" ? window : globalThis);