Train and autopilot tried in the game: prefab, wagons upright, no circling
The train piece is in the scene's prefab list, its icon is made, and the wagons keep the axis turn their FBX root brings. The autopilot gives up on a point it has circled for seven seconds without getting closer, and takes sharp turns close by slowly. -demoauto: on the easy planet the tractor unloads and goes back to mowing, and the train lays 826 m of track to Timothy, closes 532 sectors and earns about 13.7k by the time its reach is mown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -31,6 +31,9 @@ namespace GrassCutter
|
||||
int _next, _field;
|
||||
float _stuck, _back, _backSteer, _lastSteer;
|
||||
int _stuckTimes;
|
||||
/// <summary>The closest it has come to where it's going, and when: circling round a point inside its turn, it gives up on it.</summary>
|
||||
float _bestDist, _bestAt;
|
||||
int _goalKey = -1;
|
||||
Vector3 _unloadAt;
|
||||
|
||||
static readonly List<Vector2Int> s_fields = new List<Vector2Int>();
|
||||
@ -242,12 +245,23 @@ namespace GrassCutter
|
||||
|
||||
var to = Vector3.ProjectOnPlane(goal - p, up);
|
||||
float dist = to.magnitude;
|
||||
if (job == AutoJob.Mowing && dist < 1.6f)
|
||||
if (job == AutoJob.Mowing && dist < 2.2f)
|
||||
{
|
||||
_next++;
|
||||
_stuckTimes = 0;
|
||||
return new Vector2(_lastSteer, 0.4f);
|
||||
}
|
||||
int key = (int)job * 100000 + (job == AutoJob.Mowing ? _next : 0);
|
||||
if (key != _goalKey) { _goalKey = key; _bestDist = dist; _bestAt = Time.time; }
|
||||
else if (dist < _bestDist - 1f) { _bestDist = dist; _bestAt = Time.time; }
|
||||
else if (Time.time - _bestAt > 7f)
|
||||
{
|
||||
// round and round a point it can't turn into: on to the next one (or the next stroke)
|
||||
_goalKey = -1;
|
||||
if (job == AutoJob.Mowing) _next++;
|
||||
else if (++_stuckTimes >= 5) Auto.Value = (byte)AutoJob.Done;
|
||||
return new Vector2(_lastSteer, 0.4f);
|
||||
}
|
||||
|
||||
var fwd = Vector3.ProjectOnPlane(transform.forward, up).normalized;
|
||||
float ang = Vector3.SignedAngle(fwd, to, up);
|
||||
@ -265,6 +279,8 @@ namespace GrassCutter
|
||||
float cap = job == AutoJob.Mowing ? 0.7f : dist > 20f ? 1f : 0.6f;
|
||||
float thr = cap * Mathf.Lerp(1f, 0.4f, Mathf.Clamp01(Mathf.Abs(ang) / 90f));
|
||||
if (dist < 6f) thr = Mathf.Min(thr, 0.3f + dist * 0.08f);
|
||||
// a sharp turn close by is taken slowly: the slower it goes, the tighter it turns
|
||||
if (Mathf.Abs(ang) > 50f && dist < 10f) thr = Mathf.Min(thr, 0.22f);
|
||||
_lastSteer = steer;
|
||||
|
||||
if (speed < 0.5f && thr > 0.2f)
|
||||
|
||||
Reference in New Issue
Block a user