Fix the car getting stuck on the Chenaran highway
Traffic cars picked a random direction even on one-way carriageways, so some drove head-on in the player's lane and stopped dead in front of them; every bump also threw the player's car backwards while the traffic car stayed put, so the player could not get past. - Map data records one-way roads (oneway tags, motorways, roundabouts) - Traffic drives with the flow in one of two lanes on one-way roads and on the right-hand half of two-way roads, spawning only from nearby roads - Bumps slow the player down instead of reversing them; a traffic car pressed against for more than 0.8 s pulls away out of sight - Regression test for traffic direction and lanes; ?debug collision log Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,8 @@ import {toLocal, toLatLon, bearing, ORIGIN} from '../src/geo.js';
|
||||
import {createCollisionWorld, resolveCircle, blocked, clearFraction} from '../src/collision.js';
|
||||
import {buildGraph, routeBetween, nearestSegment, buildSegmentIndex} from '../src/routing.js';
|
||||
import {createCar, stepCar} from '../src/vehicle.js';
|
||||
import {createTraffic} from '../src/traffic.js';
|
||||
import {Scene} from 'three';
|
||||
import {machines, machineById, FACTORY} from '../src/locations.js';
|
||||
|
||||
const data = JSON.parse(readFileSync(new URL('../src/data/mellat.json', import.meta.url)));
|
||||
@@ -51,3 +53,16 @@ test('Car accelerates, steers right with positive input and brakes', () => {
|
||||
for (let i = 0; i < 90; i++) stepCar(car, {throttle: -1}, 1 / 30);
|
||||
assert.ok(car.speed <= 0);
|
||||
});
|
||||
|
||||
test('Traffic drives with the flow on one-way carriageways and stays inside them', () => {
|
||||
const oneway = new Set(data.oneway);
|
||||
assert.ok(data.roads.some((r, i) => data.names[r[1]]?.includes('چناران') && oneway.has(i)), 'Chenaran highway is one-way per carriageway');
|
||||
const traffic = createTraffic(new Scene(), data, 28), around = {x: -10008, z: -15049};
|
||||
for (let i = 0; i < 400; i++) traffic.update(1 / 30, [], around);
|
||||
const active = traffic.cars.filter(c => c.road);
|
||||
assert.ok(active.length > 10, `cars spawned near the player (${active.length})`);
|
||||
for (const car of active.filter(c => c.road.oneway)) {
|
||||
assert.equal(car.dir, 1);
|
||||
assert.ok(Math.abs(car.lane) < car.road.width / 2, 'lane inside the carriageway');
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user