Lights - NeisesMike/VehicleFramework GitHub Wiki

Introduction

You can use Vehicle Framework to add headlights and floodlights.

Headlights are the lights that will trigger when you right click while piloting. They light up what's visible through your viewport.

Floodlights are lights you can toggle on a Submarine's control panel. They can light any direction.

Here is an example of a good transform hierarchy for lights. Notice how each light has its own volumetric light.

https://github.com/NeisesMike/SubnauticaAtramaVehicle/blob/main/Images/wiki/hierarchy/lights_parent.png

The lights of your vehicle must have "light" in their name. This is so no shader is applied to the lights. In the lights_parent breakout image above, the example objects here are those such as the "headlights3" and "floodlights4" objects. Those objects will be appropriately skipped by Vehicle Framework.

Overview

Start by creating a top-level Game Object in your vehicle's transform hierarchy named "lights_parent." The object should be named exactly that. This is for compatibility with Tweaks and Fixes.

Every light you have also has a "Volumetric Light." The light actually provides illumination in the Unity Engine. On the other hand, the volumetric light creates the visible cone of light that you see in the water. Without the volumetric light, only the surfaces that your lights hit will be illuminated at all.

The lights_parent, headlights, and headlight1 etc are all simple transforms (empty gameobjects). They have no special components (no lights either). The only important transforms are those of individual lights like headlight1 or floodlight1. These lights must be rotated so that Z-Positive points towards where the beam of light should point. The VolumetricLight child of each light should have position and rotation identical to its parent (so that the volumetric beam matches that actual beam).

Writing the C#

The ModVehicle class has the field:

public virtual List<VehicleParts.VehicleFloodLight> HeadLights => new List<VehicleParts.VehicleFloodLight>();

The Submarine class has the field:

public virtual List<VehicleParts.VehicleFloodLight> FloodLights => null;

The VehicleParts.VehicleFloodLight struct contains all the necessary information for Vehicle Framework to turn your objects into real lights. Here is its definition:

public struct VehicleFloodLight
{
	public GameObject Light;
	public float Intensity;
	public float Range;
	public Color Color;
	public float Angle;
}

Light is the object which will actually become the lamp. Intensity is the "power" of the lamp in terms of its brightness. An intensity in the range [0,2.5f] is appropriate. Range is the "power" of the lamp in terms of its casting distance. Color is as expected. Angle is how wide the cone of light being cast is. Here are the configurations for several of the lights in Subnautica:

References

seamoth.Intensity = 1.5f;
seamoth.Range = 100;
seamoth.Angle = 50;
seamoth.Color = new Color(0.463f, 0.902f, 0.902f, 1.000f);

prawn.Intensity = 0.75f;
prawn.Range = 40;
prawn.Angle = 99;
prawn.Color = new Color(0.463f, 0.902f, 0.902f, 1.000f);

cyclops.Intensity = 2f;
cyclops.Range = 70;
cyclops.Angle = 65;
cyclops.Color = Color.white;

seaglide.Intensity = 0.9f;
seaglide.Range = 40;
seaglide.Angle = 70;
seaglide.Color = new Color(0.016, 1.000, 1.000, 1.000);

flashlight.Intensity = 1f;
flashlight.Range = 50;
flashlight.Angle = 90;
flashlight.Color = new Color(0.992, 0.992, 0.996, 1.000);

floodlightBuildable.Intensity = 0.7f;
floodlightBuildable.Range = 100;
floodlightBuildable.Angle = 85;
floodlightBuildable.Color = new Color(0.743, 0.925, 1.000, 1.000);

Headlights

These lights will be the ones used for piloting. That is, when you're driving this vehicle and you RightHandDown, these lights will be toggled. In addition, Vehicle Framework will automatically connect the headlights to the control panel for you if your vehicle is a Submarine.

Floodlights

As above, but these lights must be toggled via the control panel. Vehicle Framework will connect these lights to the control panel automatically. Their intended use is as lights used to illuminate the environment on a large scale. That is, these lights might not be useful for piloting, but they might be useful for exploration. Because the vehicle will automatically balance itself out when not being driven, these lights should probably point downward.