Since the light is loaded by the player's opr, it will follow the rotation of the player with no effort from us. However, since our player only rotates left and right we need to manually set the vertical (or Up Down) rotation. The character.gsl is already tracking this for the camera, so all we need to do is access that info.
Inside...
bool HandleEvent( Object@ object, const String& in event, GameEventParams@ params)
{
You need the following (which should already be in your character.gsl, unless you've changed it. The comments are added by me to help explain how this works.
if (params.stringValue == "MouseRelativeX")
{
lookLeftRight += params.floatValue * mouseMult;
return true;
}
if (params.stringValue == "MouseRelativeY")
{
lookUpDown -= params.floatValue * mouseMult;
if (lookUpDown < -85)
lookUpDown = -85;
if (lookUpDown > 85)
lookUpDown = 85;
return true;
}
/* MouseRelativeX and Mouse RelativeY should be declared in input.cfg. As their names imply, they track the mouse's movement
lookLeftRight is a variable float declared at the top of the script. This will store where MouseRelativeX is.
mouseMult is a const float also declared at the top. mouseMult = 180/PI converts the params given by MouseRelativeX and Y to degrees
lookUpDown is also a variable float decared at the top of the script. This will store where MouseRelativeY is.
Basically, what this section does is track the mouse's movement, and then limit the vertical mouse movement to only 85 degrees up or down. */
So now we just grab our light and access the vertical mouse movement stored in "lookUpDown" to set our light's rotation.
Light@ light = object.GetLight("Flashlight");
light.SetRotationEuler(Vector( 0, 180 + lookUpDown , 0));
/* 180 + lookUpDown is used to invert the rotation of the light. Just using lookUpDown without inverting it, causes the light to go down when you go up and vice versa. We don't set the X or Z of the rotation because the light is automatically following the player's rotation for those axis */
I hope that helped explain things some.
