Now we have an understanding of how these lights work, but so far, they've all been static, non-moving. However, in certain instances, we may want the lighting to change while the game is going on. Let's do that by creating a moving light, in a similar manner to a flashlight!
Before we start working, we should have the NightScene
level opened. This is provided in the Example Code
folder for this chapter that you can get off of Packt's website.
This level is a quick example of a night environment with the lighting reduced significantly. For more information on creating a scene using lighting for night time, refer to https://docs.unrealengine.com/latest/INT/Resources/Showcases/RealisticRendering/NightScene/index.html.
To create a flashlight, perform the following steps:
SpotLight
to use as our flashlight. We can do that by right-clicking on the ground near the player and then navigating to Place Actor | Spot Light.8
and the Outer Cone Angle value to 10
. Lastly, we want this actor to be movable so that it can move, so in the Details tab under Transform | Mobility, select the option that is the furthest to the right (Movable).For more information on moveable lights, refer to https://docs.unrealengine.com/latest/INT/Engine/Rendering/LightingAndShadows/LightMobility/DynamicLights/index.html.
MyCharacter_C4
(or something similar). Select it and scroll down to your SpotLight
. Drag and drop the SpotLight
object on top of the MyCharacter
object (use the mouse wheel to move the object selections up while holding down the mouse).SpotLight
to 0,0,0
so that it is at the same position of the player. (As we mentioned before, children of an object have a transition relative to the position of their parent.)As you can see, we now have a working flashlight in Unreal. There are a few issues with this, for example, if we look up or down, the light will not go with us because the camera has a different transform than our Character
class. There's also the issue that since we did this in the game (after the player has been spawned), when we will leave, it'll reset to what it was beforehand. We know that the functionality is possible now, so how can we make this work all the time, and have functionality? Adding it to our Character's Blueprint, we'll dive into how to do this exactly, and the other things to to be considered in our Adding to an existing Blueprint – flashlight, part 2 recipe, which you can find in Chapter 8,
Blueprint Scripting – Level Effects.
3.142.153.224