Round 6 fixes: held tools, headlamp glare, ladder openings, level horizon, roof hulls, rain hits, idle motion, belt packs, meadow variety
- Held tools sit lower and further right; the hammer faces forward and strikes about the camera's right - Headlamp leaves held items, treats and vending machines alone (rendering layer NoLamp); other lights keep lighting them - Hay grounded on the floor in world space (it floated) - Deck fence opens at each ladder, rail colliders split around it; ladders moved to 2 m off the edge middle, clear of the intakes; climbing goes over a rail only if one is in the way - Crew stand to the soil's up (Planet.Level): flat round the base, the ball's up past it, so the horizon stays level on a small planet - Convex roof hulls for the crew cabin, garage, pitched roof and windmill tower; cabin box lowered to the eaves - Rain and acid rain hits differ by surface: soil, grass, wood, metal - Idle motion: dishes pan, sways sway, sensors turn, eyes blink, windmill turns in the breeze, reels and parked rotors tick over - Belt: take tools off at the supply wall; hold E at a vending machine for a pack of 3 on the belt, LMB has one - New meadow pieces: boulders, slab stones, crystals, mushrooms, stump, bulb plants - -demofix checks for all of the above; loc rows in all 11 tables Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -72,6 +72,17 @@ namespace GrassCutter
|
||||
static readonly Color NightSky = new Color(0.13f, 0.17f, 0.3f), NightMid = new Color(0.09f, 0.12f, 0.21f), NightLow = new Color(0.05f, 0.07f, 0.11f);
|
||||
|
||||
Light _sun, _lamp;
|
||||
|
||||
/// <summary>Rendering layer of things the headlamp leaves alone: whatever is held right in front of the eyes
|
||||
/// and machines with lights of their own, which it only blew out to white. The sun and the lampposts still light them.</summary>
|
||||
public const int NoLamp = 1 << 1;
|
||||
|
||||
public static void KeepOutOfLamp(GameObject root)
|
||||
{
|
||||
foreach (var r in root.GetComponentsInChildren<Renderer>(true)) r.renderingLayerMask = NoLamp;
|
||||
// a machine's own lights still light it
|
||||
foreach (var l in root.GetComponentsInChildren<Light>(true)) l.renderingLayerMask |= NoLamp;
|
||||
}
|
||||
float _sunPower;
|
||||
Color _sunColor, _fog, _sky, _mid, _low;
|
||||
ColorAdjustments _grade;
|
||||
@ -153,7 +164,12 @@ namespace GrassCutter
|
||||
_lamp.range = LampRange;
|
||||
_lamp.color = new Color(1f, 0.95f, 0.85f);
|
||||
_lamp.shadows = LightShadows.None;
|
||||
_lamp.renderingLayerMask = ~NoLamp;
|
||||
// every other light keeps lighting what the headlamp leaves alone
|
||||
foreach (var l in FindObjectsByType<Light>(FindObjectsInactive.Include))
|
||||
if (l != _lamp) l.renderingLayerMask |= NoLamp;
|
||||
}
|
||||
if (_sun && _sun.renderingLayerMask != -1) _sun.renderingLayerMask = -1;
|
||||
var from = Rig ? Rig : cam.transform;
|
||||
_lamp.transform.SetParent(from, false);
|
||||
// a machine's floodlights join in while you drive it
|
||||
|
||||
@ -8,6 +8,9 @@ namespace GrassCutter
|
||||
{
|
||||
public static DeckManager Instance { get; private set; }
|
||||
public GameObject tileModel, ladderModel;
|
||||
/// <summary>How far along each open edge from its middle the ladder hangs: clear of the intakes at the middle of
|
||||
/// the edge tiles, in the opening the fence model leaves for it.</summary>
|
||||
public const float LadderAt = 2.0f;
|
||||
/// <summary>Deck-edge points that must stay open (the dock): the railing on that side of the tile is left out.</summary>
|
||||
public Vector3[] gaps;
|
||||
readonly Dictionary<int, DeckTileView> _views = new Dictionary<int, DeckTileView>();
|
||||
@ -129,10 +132,26 @@ namespace GrassCutter
|
||||
return bc;
|
||||
}
|
||||
float h = 1.0f, e = S * 0.5f - 0.12f;
|
||||
v.colN = Rail("RailN", new Vector3(0, h * 0.5f, e), new Vector3(S, h, 0.1f));
|
||||
v.colS = Rail("RailS", new Vector3(0, h * 0.5f, -e), new Vector3(S, h, 0.1f));
|
||||
v.colE = Rail("RailE", new Vector3(e, h * 0.5f, 0), new Vector3(0.1f, h, S));
|
||||
v.colW = Rail("RailW", new Vector3(-e, h * 0.5f, 0), new Vector3(0.1f, h, S));
|
||||
// each railing stops either side of its ladder: the opening the fence model leaves there. The part of the rail
|
||||
// beside the opening (the short piece out to the corner) is its own child of the main one, so SetEdges toggles both
|
||||
float gapMid = LadderAt, gapHalf = 0.48f;
|
||||
float lenA = S * 0.5f + gapMid - gapHalf, lenB = S * 0.5f - gapMid - gapHalf;
|
||||
BoxCollider Split(string n, Vector3 normal, Vector3 along)
|
||||
{
|
||||
// `along` points from the corner at -S/2 to the one at +S/2; the ladder sits at +gapMid along it
|
||||
var a = Rail(n, normal * e + Vector3.up * h * 0.5f + along * (-S * 0.5f + lenA * 0.5f), Abs(along * lenA) + Abs(normal) * 0.1f + Vector3.up * h);
|
||||
var b = new GameObject(n + "_b") { layer = Physics.IgnoreRaycastLayer };
|
||||
b.transform.SetParent(a.transform, false);
|
||||
b.transform.position = a.transform.parent.TransformPoint(normal * e + Vector3.up * h * 0.5f + along * (S * 0.5f - lenB * 0.5f));
|
||||
b.AddComponent<BoxCollider>().size = Abs(along * lenB) + Abs(normal) * 0.1f + Vector3.up * h;
|
||||
return a;
|
||||
}
|
||||
static Vector3 Abs(Vector3 v) => new Vector3(Mathf.Abs(v.x), Mathf.Abs(v.y), Mathf.Abs(v.z));
|
||||
// ladder spots: N at x = -LadderAt, S at x = +LadderAt, E at z = +LadderAt, W at z = -LadderAt
|
||||
v.colN = Split("RailN", Vector3.forward, Vector3.left);
|
||||
v.colS = Split("RailS", Vector3.back, Vector3.right);
|
||||
v.colE = Split("RailE", Vector3.right, Vector3.forward);
|
||||
v.colW = Split("RailW", Vector3.left, Vector3.back);
|
||||
// ladders down to the meadow on every open edge (shown by SetEdges)
|
||||
if (ladderModel)
|
||||
{
|
||||
@ -146,10 +165,10 @@ namespace GrassCutter
|
||||
l.transform.localRotation = Quaternion.Euler(0, yaw, 0) * ladderModel.transform.localRotation;
|
||||
}
|
||||
// front of the ladder model hangs toward -Y Blender = +Z Unity (yaw 0 → toward +Z)
|
||||
L(new Vector3(-1.5f, 0f, S * 0.5f), 0f);
|
||||
L(new Vector3(1.5f, 0f, -S * 0.5f), 180f);
|
||||
L(new Vector3(S * 0.5f, 0f, 1.5f), 90f);
|
||||
L(new Vector3(-S * 0.5f, 0f, -1.5f), 270f);
|
||||
L(new Vector3(-LadderAt, 0f, S * 0.5f), 0f);
|
||||
L(new Vector3(LadderAt, 0f, -S * 0.5f), 180f);
|
||||
L(new Vector3(S * 0.5f, 0f, LadderAt), 90f);
|
||||
L(new Vector3(-S * 0.5f, 0f, -LadderAt), 270f);
|
||||
}
|
||||
foreach (var t in go.GetComponentsInChildren<Transform>(true)) t.gameObject.isStatic = false;
|
||||
_views[packed] = v;
|
||||
|
||||
@ -16,7 +16,7 @@ namespace GrassCutter
|
||||
void Set(GameObject rail, BoxCollider col, bool open)
|
||||
{
|
||||
if (rail) rail.SetActive(open);
|
||||
if (col) col.enabled = open;
|
||||
if (col) col.gameObject.SetActive(open); // the rail's collider and the short piece past the ladder opening
|
||||
}
|
||||
Set(railN, colN, n); Set(railS, colS, s); Set(railE, colE, e); Set(railW, colW, w);
|
||||
if (ladderRoot)
|
||||
|
||||
@ -18,6 +18,9 @@ namespace GrassCutter
|
||||
public GameObject[] spires = new GameObject[3];
|
||||
public GameObject[] trees = new GameObject[3];
|
||||
public GameObject bush;
|
||||
/// <summary>More than trees and spires: field stones, slabs and crystals (they stay), and mushrooms, a stump and
|
||||
/// bulb plants (they come down with the trees when their sector is mown clean).</summary>
|
||||
public GameObject[] stones = new GameObject[0], growths = new GameObject[0];
|
||||
|
||||
const int Rings = 112, Spokes = 192, WildRocks = 800, Groves = 110;
|
||||
const float FirstRing = 1f, RingGrowth = 1.06f, RockDraw = 1800f;
|
||||
@ -352,6 +355,49 @@ namespace GrassCutter
|
||||
Place(trees[rng.Next(3)], at, R(0f, 360f), R(1.2f, 2.2f), true, true);
|
||||
}
|
||||
}
|
||||
Scatter();
|
||||
}
|
||||
|
||||
/// <summary>Stones and odd growths over the meadow: a few round the clearing, the rest anywhere on the ball. A separate
|
||||
/// sequence of its own, so the spires and the trees stand where they always have.</summary>
|
||||
void Scatter()
|
||||
{
|
||||
var rng = new System.Random(9311);
|
||||
float R(float a, float b) => a + (float)rng.NextDouble() * (b - a);
|
||||
bool any = false;
|
||||
foreach (var g in stones) any |= g;
|
||||
foreach (var g in growths) any |= g;
|
||||
if (!any) return;
|
||||
GameObject Pick(GameObject[] set) => set.Length > 0 ? set[rng.Next(set.Length)] : null;
|
||||
// close by, where the crew sees them from the first minute
|
||||
for (int i = 0; i < 26; i++)
|
||||
{
|
||||
float a = R(0f, Mathf.PI * 2f), d = R(55f, 150f);
|
||||
var dir = Planet.FromBase(Mathf.Cos(a) * d, Mathf.Sin(a) * d);
|
||||
bool stone = rng.NextDouble() < 0.5;
|
||||
var p = Pick(stone ? stones : growths);
|
||||
if (!p) continue;
|
||||
// the bulb plants are walked through; everything else is solid
|
||||
Place(p, dir, R(0f, 360f), stone ? R(0.8f, 1.6f) : R(0.9f, 1.5f), p.name != "SM_BulbPlants", !stone);
|
||||
}
|
||||
int far = Mathf.Max(40, Mathf.RoundToInt(420 * Planet.Scale * Planet.Scale));
|
||||
for (int i = 0; i < far; i++)
|
||||
{
|
||||
var dir = new Vector3(R(-1f, 1f), R(-1f, 1f), R(-1f, 1f)).normalized;
|
||||
if (dir.y > 0.985f) continue;
|
||||
bool stone = rng.NextDouble() < 0.55;
|
||||
var p = Pick(stone ? stones : growths);
|
||||
if (!p) continue;
|
||||
// they come in little clusters of two or three
|
||||
var e1 = Vector3.Cross(dir, Vector3.right).normalized;
|
||||
var e2 = Vector3.Cross(dir, e1);
|
||||
int n = rng.Next(1, 4);
|
||||
for (int k = 0; k < n; k++)
|
||||
{
|
||||
var at = (dir + (e1 * R(-9f, 9f) + e2 * R(-9f, 9f)) / Planet.Radius).normalized;
|
||||
Place(p, at, R(0f, 360f), stone ? R(0.7f, 2.2f) : R(0.8f, 1.7f), p.name != "SM_BulbPlants", !stone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>70 m round each far station, on any ball.</summary>
|
||||
|
||||
83
Assets/Scripts/World/IdleMotion.cs
Normal file
83
Assets/Scripts/World/IdleMotion.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GrassCutter
|
||||
{
|
||||
/// <summary>
|
||||
/// The small life of things standing about: a dish panning slowly over the sky, a windsock or a whip aerial swaying (more
|
||||
/// in a wind), a sensor turning, robot eyes blinking now and then. Parts are found by the names the models give them
|
||||
/// (Dish, Sway*, SpinSensor, Blink*); anything another script already drives is left to it.
|
||||
/// </summary>
|
||||
public class IdleMotion : MonoBehaviour
|
||||
{
|
||||
struct Part
|
||||
{
|
||||
public Transform t;
|
||||
public int kind; // 0 dish, 1 sway, 2 spin, 3 blink
|
||||
public Vector3 axis, scale;
|
||||
public float phase;
|
||||
}
|
||||
|
||||
readonly List<Part> _parts = new List<Part>();
|
||||
float _blinkAt;
|
||||
|
||||
/// <summary>Adds the motion to whatever under root has parts for it; nothing if there are none.</summary>
|
||||
public static void Attach(GameObject root)
|
||||
{
|
||||
if (root && !root.GetComponent<IdleMotion>()) root.AddComponent<IdleMotion>();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
// a mowbot looks after its own spinning, swaying and blinking
|
||||
bool bot = GetComponentInChildren<Mowbot>(true);
|
||||
var up = transform.up;
|
||||
foreach (var t in GetComponentsInChildren<Transform>(true))
|
||||
{
|
||||
var n = t.name;
|
||||
int kind = n == "Dish" ? 0 : n.StartsWith("Sway") ? 1 : n == "SpinSensor" ? 2 : n.StartsWith("Blink") ? 3 : -1;
|
||||
if (kind < 0 || (bot && kind != 0)) continue;
|
||||
int ax = BaseRot.LocalAxisFor(t, kind == 1 ? transform.right : up);
|
||||
var axis = ax == 0 ? Vector3.right : ax == 1 ? Vector3.up : Vector3.forward;
|
||||
BaseRot.Of(t);
|
||||
_parts.Add(new Part { t = t, kind = kind, axis = axis, scale = t.localScale, phase = Random.value * 20f });
|
||||
}
|
||||
if (_parts.Count == 0) { enabled = false; return; }
|
||||
_blinkAt = Time.time + Random.Range(2f, 6f);
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
float time = Time.time;
|
||||
float wind = WeatherFx.Wind;
|
||||
bool blink = false;
|
||||
if (time >= _blinkAt)
|
||||
{
|
||||
blink = time < _blinkAt + 0.14f;
|
||||
if (!blink) _blinkAt = time + Random.Range(2.5f, 7f);
|
||||
}
|
||||
foreach (var p in _parts)
|
||||
{
|
||||
if (!p.t) continue;
|
||||
switch (p.kind)
|
||||
{
|
||||
case 0:
|
||||
// a slow look round the sky, resting a while at each end
|
||||
float pan = Mathf.SmoothStep(-1f, 1f, Mathf.PingPong((time + p.phase) / 9f, 1f)) * 22f;
|
||||
p.t.localRotation = BaseRot.Of(p.t) * Quaternion.AngleAxis(pan, p.axis);
|
||||
break;
|
||||
case 1:
|
||||
float a = (Mathf.Sin(time * 1.7f + p.phase) * 0.6f + Mathf.Sin(time * 2.9f + p.phase * 1.3f) * 0.4f) * (3f + wind * 14f);
|
||||
p.t.localRotation = BaseRot.Of(p.t) * Quaternion.AngleAxis(a, p.axis);
|
||||
break;
|
||||
case 2:
|
||||
p.t.localRotation = BaseRot.Of(p.t) * Quaternion.AngleAxis((time + p.phase) * 45f, p.axis);
|
||||
break;
|
||||
case 3:
|
||||
p.t.localScale = blink ? Vector3.Scale(p.scale, Vector3.one - p.axis * 0.85f) : p.scale;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/World/IdleMotion.cs.meta
Normal file
2
Assets/Scripts/World/IdleMotion.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 51865f698a1604544a299f2935db2195
|
||||
@ -69,6 +69,20 @@ namespace GrassCutter
|
||||
public static Quaternion Frame { get; private set; } = Quaternion.identity;
|
||||
|
||||
public static Vector3 Up(Vector3 p) => (p - Center).normalized;
|
||||
|
||||
/// <summary>
|
||||
/// Which way the soil itself faces: straight up on the flat the base stands on, the ball's own up out past it, blended
|
||||
/// across the ring where the flat bends down onto the ball. Standing to this keeps the horizon level: on a small
|
||||
/// ball the flat's far side leans tens of degrees off the ball's up, and a head stood to the ball saw it tilted.
|
||||
/// </summary>
|
||||
public static Vector3 Level(Vector3 p)
|
||||
{
|
||||
var up = Up(p);
|
||||
float s = Mathf.Sqrt(Mathf.Max(0f, 2f - 2f * up.y)) * Radius;
|
||||
if (s >= ClearB) return up;
|
||||
if (s <= ClearA) return Vector3.up;
|
||||
return Vector3.Slerp(Vector3.up, up, Mathf.SmoothStep(0f, 1f, (s - ClearA) / (ClearB - ClearA))).normalized;
|
||||
}
|
||||
public static Vector3 OnSurface(Vector3 dir) => Center + dir * (Radius + HeightAt(dir));
|
||||
public static Vector3 Surface(Vector3 p) => OnSurface(Up(p));
|
||||
public static bool InNorthCap(Vector3 p) => p.y > NorthCapY;
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
@ -186,18 +187,64 @@ namespace GrassCutter
|
||||
var at = ground + Planet.Frame * new Vector3(o.x, 0f, o.y) + up * (lift + Random.Range(0f, 6f)) - windDir * 4f;
|
||||
Fx.Emit(_drops, at, fall * Random.Range(0.9f, 1.1f), Random.Range(0.045f, 0.07f), tint, (lift + 3f) / 24f);
|
||||
}
|
||||
_splashDue += dt * 70f * r;
|
||||
_splashDue += dt * 110f * r;
|
||||
for (; _splashDue >= 1f; _splashDue -= 1f)
|
||||
{
|
||||
// where a drop lands: on whatever stands there (deck, roof, machine), else on the soil
|
||||
var o = Random.insideUnitCircle * 12f;
|
||||
var at = Planet.Surface(eye + Planet.Frame * new Vector3(o.x, 0f, o.y));
|
||||
if (Vector3.Dot(eye - at, up) > 25f) break;
|
||||
var on = Fx.Surface.Ground;
|
||||
if (Physics.Raycast(at + up * 30f, -up, out var hit, 31f, HitMask, QueryTriggerInteraction.Ignore) && Vector3.Dot(hit.point - at, up) > -0.05f)
|
||||
{
|
||||
at = hit.point;
|
||||
on = SurfaceOf(hit.collider);
|
||||
}
|
||||
else if (MowMap.Yield(at) > 0.3f) on = Fx.Surface.Grass;
|
||||
Fx.Emit(_splash, at + up * 0.05f, up * 0.4f, Random.Range(0.08f, 0.16f), new Color(tint.r, tint.g, tint.b, 0.5f));
|
||||
Fx.RainHit(at, up, on, tint, Acid);
|
||||
}
|
||||
}
|
||||
Volume(ref _rainLoop, "rain_loop", r * (0.55f + Storm * 0.25f));
|
||||
}
|
||||
|
||||
const int HitMask = (1 << Layers.Default) | (1 << Layers.Build) | (1 << Layers.Vehicle) | (1 << Layers.Prop);
|
||||
|
||||
static readonly Dictionary<Collider, Fx.Surface> s_surface = new Dictionary<Collider, Fx.Surface>();
|
||||
|
||||
/// <summary>What a collider is made of, as far as rain can tell: machines and vehicles are metal, the deck and what is
|
||||
/// built of planks is wood, anything else by its material's name.</summary>
|
||||
static Fx.Surface SurfaceOf(Collider c)
|
||||
{
|
||||
if (s_surface.TryGetValue(c, out var k)) return k;
|
||||
k = Fx.Surface.Ground;
|
||||
if (c.gameObject.layer == Layers.Vehicle || c.GetComponentInParent<Vehicle>()) k = Fx.Surface.Metal;
|
||||
else if (c.GetComponentInParent<DeckTileView>()) k = Fx.Surface.Wood;
|
||||
else if (c.GetComponentInParent<BuildPiece>() is BuildPiece bp)
|
||||
{
|
||||
switch (bp.piece)
|
||||
{
|
||||
case PieceId.Wall: case PieceId.WindowWall: case PieceId.DoorWall: case PieceId.Railing: case PieceId.Fence:
|
||||
case PieceId.Floor: case PieceId.FlatRoof: case PieceId.Roof: case PieceId.Stairs: case PieceId.Steps:
|
||||
case PieceId.Pillar: case PieceId.Planter: case PieceId.Bench: case PieceId.Crates: case PieceId.Square: case PieceId.Hex:
|
||||
k = Fx.Surface.Wood; break;
|
||||
default: k = Fx.Surface.Metal; break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var r = c.GetComponent<Renderer>();
|
||||
if (!r) r = c.GetComponentInParent<Renderer>();
|
||||
if (!r && c.transform.parent) r = c.transform.parent.GetComponentInChildren<Renderer>();
|
||||
var n = r && r.sharedMaterial ? r.sharedMaterial.name.ToLowerInvariant() : c.name.ToLowerInvariant();
|
||||
if (n.Contains("metal") || n.Contains("iron") || n.Contains("steel") || n.Contains("hull") || n.Contains("tin") || n.Contains("chrome") || n.Contains("paint")) k = Fx.Surface.Metal;
|
||||
else if (n.Contains("wood") || n.Contains("plank") || n.Contains("timber") || n.Contains("log") || n.Contains("bark") || n.Contains("tree") || n.Contains("hay") || n.Contains("deck")) k = Fx.Surface.Wood;
|
||||
}
|
||||
if (s_surface.Count > 4000) s_surface.Clear();
|
||||
s_surface[c] = k;
|
||||
return k;
|
||||
}
|
||||
|
||||
void TickWind(Vector3 eye, Vector3 up, Vector3 windDir, float dt)
|
||||
{
|
||||
float w = Mathf.Max(Wind, Storm * 0.6f);
|
||||
|
||||
Reference in New Issue
Block a user