Update sun position using mousewheel - Epic Wiki

# Update sun position using mousewheel

Rate this Article:

0.00

Approved for Versions:(please verify)

# Overview

In this tutorial we will create a Blueprint setup (Level Blueprint) in which you can update the sun position (both pitch and yaw) using mouse scroll up and down. To update the pitch you'll use Mouse Scroll Up/Down and with CTRL pressed you can update the Yaw. When ALT is pressed you can speed up this movement.

First add Movable Directional Light in your viewport

# Level Blueprint

Open your Level Blueprint and create a new Rotator variable and name it SunRotation. When you begin play, the directional light rotation from your level is saved to this variable so you can freely move the sun inside your viewport and still update it at runtime.

StepI.jpg

Now create a new float variable with name RotationValue. We will later use this variable to update suns rotation.

RJ2040 SunBP StepRotationValue.jpg

Then create a new Event BeginPlay node and connect like this. NOTE: I am using a Blueprinted DirectionalLight. You may not want to do this. Instead you can simply add a reference to your Sun by selecting it in viewport and right click in Level Blueprint and select Add Reference to Sun.

RJ2040 SunBP EventBeginPlay.jpg

Now create series of nodes as shown below. Once i created the nodes i collapsed them all. NOTE: You may not want to add Print Node. I added it just for debugging only.

  • RJ2040 SunBP RotationADD NotCollapsed.jpg

  • RJ2040 SunBP RotationADD NotCollapsed2.jpg

Now you need to create two events for MouseScrollUP and for one of them make sure to enable Control modifier. Do the same for MouseScrollDown. Then connect the output rotation to Set Rotation node (make sure the target is connected to your sun).

RJ2040 SunBP Connections.jpg

Thats it! Jump into game and use your mouse wheel to dynamically update Sun position.

# Make the sun go faster

We use the bAltPressed boolean variable to see if the user has pressed the Alt Key. We will use this variable inside those collapsed nodes to check if we want the sun to move faster or not. Setup like this somewhere inside Level Blueprint.

TJ2040 SunBP bAltPressed.jpg

Retrieved from "https://wiki.unrealengine.com/index.php?title=Update_sun_position_using_mousewheel&oldid=8323"

Categories:

Hidden category: