Game Development Reference
In-Depth Information
Adding a light
Our plane isn't very exciting, as the sandbox has no lighting. The core package provides ad-
ditional functions that create a directional light and assign diffuse and specular colors. The
Core.CreateDirectionalLight function requires two parameters, the sandbox and
a vector representing the direction of the light. Using a vector of (1, -1, 1) will create
a light source that points diagonally in a downward direction.
Sandbox.lua :
function Sandbox_Initialize(sandbox)
...
local directional = Core.CreateDirectionalLight(
sandbox, Vector.new(1, -1, 1));
--- Color is represented by a red, green, and blue
vector.
Core.SetLightDiffuse(
directional, Vector.new(1.8, 1.4, 0.9));
Core.SetLightSpecular(
directional, Vector.new(1.8, 1.4, 0.9));
end
Tip
Note that the color of the diffuse and specular light values defined by Vect-
or.new(red, green, blue) are set to values above one. This allows you to change
the amount of light emitted.
Now that we have a light source, you can run your sandbox and look at the beautiful plane
you created. To orient the camera, simply hold the right mouse button and drag the mouse
in the direction in which you would like to point the camera. To navigate through the sand-
box, we can move the camera around the world using the w , a , s , and d keys. Holding the
Shift key while pressing any of the w , a , s , and d keys will move the camera significantly
faster.
Search WWH ::




Custom Search