Wagons on the rails, buildings on the slope, an autopilot nothing stops
- The train's loco and wagons stand on their front and back axles, so they pitch with the track up and down hills instead of standing level and hanging off one end; wheels sit on the rail tops, gauge matched to the models. - A piece set down on the soil leans with the ground under its footprint (up to 22 degrees) and sinks until no corner hangs in the air; foundations stay level. - On autopilot a machine touches nothing: it rides on the soil and the base deck and drives straight through buildings, rocks, rails, people and machines. Wedged anyway, it hops a few metres on; it no longer gives up on the way to unload. - -demoauto puts a building in the way to the yard, sets one down on the steepest clear slope and reports any tip-over. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -25,7 +25,9 @@ namespace GrassCutter
|
||||
const float Strip = 3.4f, Arm = 3f;
|
||||
/// <summary>How far out the side cutters reach at Mk I, either side of the track.</summary>
|
||||
const float Reach = 18f;
|
||||
const float WaitAtEnd = 6f, Hold = 6000f, Gap = 5.2f, Gauge = 1.5f;
|
||||
const float WaitAtEnd = 6f, Hold = 6000f, Gap = 5.2f, Gauge = 1.62f;
|
||||
/// <summary>The top of the rails above the track line: the models' wheels stand on their origin.</summary>
|
||||
const float RailTop = 0.27f;
|
||||
|
||||
/// <summary>The station it is laying track to (255: not chosen yet).</summary>
|
||||
public readonly NetworkVariable<byte> Target = new NetworkVariable<byte>(255);
|
||||
@ -47,7 +49,7 @@ namespace GrassCutter
|
||||
float Mul => (Piece ? Piece.TierMul : 1f) * (Ts ? Ts.BotSpeedMul : 1f);
|
||||
float MaxOut => Reach * (Piece ? Piece.TierMul : 1f);
|
||||
/// <summary>Where the train stands at home: far enough along for every wagon to be on the rails.</summary>
|
||||
float HomeAt => Mathf.Min(_length, (wagons != null ? wagons.Length : 0) * Gap + 1f);
|
||||
float HomeAt => Mathf.Min(_length, (wagons != null ? wagons.Length : 0) * Gap + 2.5f);
|
||||
float Inner => Strip * 0.5f + (Runs.Value - 1) * Arm;
|
||||
bool Laying => Laid.Value < _length - 0.01f;
|
||||
bool RouteDone => !Laying && Runs.Value > 0 && Inner >= MaxOut;
|
||||
@ -72,6 +74,10 @@ namespace GrassCutter
|
||||
var mf = t.GetComponent<MeshFilter>();
|
||||
float rad = mf && mf.sharedMesh ? Mathf.Max(0.1f, mf.sharedMesh.bounds.extents.y) : 0.4f;
|
||||
_wheels.Add((t, t.localRotation, rad));
|
||||
// how far the axles reach fore and aft: the model sits on the rails at its end axles
|
||||
var lp = Vector3.Scale(root.InverseTransformPoint(t.position), root.localScale);
|
||||
float z = Mathf.Abs((root.localRotation * lp).z);
|
||||
_axles[root] = Mathf.Max(_axles.TryGetValue(root, out var had) ? had : 0f, z);
|
||||
}
|
||||
else if (t.name == "Reel") { _reel = t; _reelRest = t.localRotation; }
|
||||
}
|
||||
@ -151,6 +157,14 @@ namespace GrassCutter
|
||||
_length = _cum[_cum.Count - 1];
|
||||
}
|
||||
|
||||
/// <summary>The point this far along the track, carried on straight past either end.</summary>
|
||||
Vector3 PosOn(float d)
|
||||
{
|
||||
if (d < 0f) return Pos(0f) - Ahead(0f) * -d;
|
||||
if (d > _length) return Pos(_length) + Ahead(_length) * (d - _length);
|
||||
return Pos(d);
|
||||
}
|
||||
|
||||
/// <summary>The point this far along the track.</summary>
|
||||
Vector3 Pos(float d)
|
||||
{
|
||||
@ -276,15 +290,27 @@ namespace GrassCutter
|
||||
/// <summary>How each model stands in its own frame (an FBX with one root object brings its axis turn on that root).</summary>
|
||||
readonly Dictionary<Transform, Quaternion> _rest = new Dictionary<Transform, Quaternion>();
|
||||
|
||||
readonly Dictionary<Transform, float> _axles = new Dictionary<Transform, float>();
|
||||
|
||||
/// <summary>
|
||||
/// Stands a model on the rails: its front and back axles both on the track, so it leans up and down the slopes
|
||||
/// with the rails instead of standing level and hanging off one end.
|
||||
/// </summary>
|
||||
void Place(Transform t, float d, bool onRails)
|
||||
{
|
||||
if (!t) return;
|
||||
if (!_rest.TryGetValue(t, out var rest)) _rest[t] = rest = t.localRotation;
|
||||
var p = Pos(d);
|
||||
var up = Planet.Up(p);
|
||||
var f = Vector3.ProjectOnPlane(Ahead(d), up);
|
||||
if (f.sqrMagnitude < 1e-6f) f = Vector3.ProjectOnPlane(transform.forward, up);
|
||||
t.SetPositionAndRotation(p + up * (onRails ? 0.22f : 0f), Quaternion.LookRotation(f.normalized, up) * rest);
|
||||
float half = _axles.TryGetValue(t, out var ax) && ax > 0.2f ? ax : 1.5f;
|
||||
var back = PosOn(d - half);
|
||||
var front = PosOn(d + half);
|
||||
var f = front - back;
|
||||
if (f.sqrMagnitude < 1e-4f) f = Ahead(d);
|
||||
f.Normalize();
|
||||
var mid = (back + front) * 0.5f;
|
||||
var up = Vector3.ProjectOnPlane(Planet.Up(mid), f);
|
||||
if (up.sqrMagnitude < 1e-6f) up = Planet.Up(mid);
|
||||
up.Normalize();
|
||||
t.SetPositionAndRotation(mid + up * (onRails ? RailTop : 0f), Quaternion.LookRotation(f, up) * rest);
|
||||
}
|
||||
|
||||
// ───────────────────────── the track ─────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user