Adding moveable lights – flashlight, part 1

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!

Getting ready

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.

Getting ready

The NightScene level

Note

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.

How to do it…

To create a flashlight, perform the following steps:

  1. The first thing we will want to do is create a 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.
  2. Rotate the spotlight 90 degrees so that it is facing away from the player's spawn point. Then, change the Inner Cone Angle value to 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).
    How to do it…

    Adjusting the cone angles of the spot light and making the player movable

  3. Now if you play the game, you will see additional objects in the Scene Outliner tab, including an object called 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).
  4. After this, set the Location value of the 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.)
    How to do it…

    Setting the Location value of the spot light

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.153.224