No announcement yet.

Vertical Rotation Flashlight Working

  • Filter
  • Time
  • Show
Clear All
new posts

    Vertical Rotation Flashlight Working

    After 2 days, my first serious experience with Unreal, I have created a Toggleable flashlight that even follows vertical motion. And it is mostly built in Kismet. So because I have poured hours through the internet reading references, code examples, tutorials, videos, etc that many of you guys and others have created I too wish to pay it forward. For the pro's in here, PLEASE critique the work I have done, I want to make sure I do it right/better!!!

    1. First I modified in a console command to the DefaultInput.ini. This will send a message through the console that Kismet can pick up through a node. I didn't want feign death in the little game/level I was creating, so below is an example that actually replaces the f key alltogether:
    .Bindings=(Name="F",Command="causeevent toggleFlashLight")
    2. The next part is relatively easy and you can find plenty of references on the internet on how to get this done. Basically, I created a Movable Spotlight and messed with its cone settings. Additionally, in Kismet Matinee, I set 1 end of this Spotlight's brightness animation to 0 and the other end of the animation to a higher value. This would become a toggle that reads the "toggleFlashLight" from the previous step. Make sure you make the Console Event's Max Trigger Count to 0 and Matinee Looping Checked Off. I hooked this part of the system up like so:

    3. Because Kismet does not recognize the player's view pitch (or I must've not been aware of any other way), I had to create my own Kismet script that would input an object and output a float variable (probably should have been int). Anyways, I would most appreciate if anyone had any suggestions on how to optimize and better code the following since it had a handler warning on it and I'm relatively new at this:

    class ShipSeqAct_GetPitch extends SequenceAction;
    var float FloatResult;
    event Activated()
    	local SeqVar_Object ObjVar;
    	local Pawn P; //Var For Target Pawn.
    	local Rotator ViewRotation; //Var To Store View Rotation.
    	foreach LinkedVariables(class'SeqVar_Object', ObjVar, "Target")
    		P = Pawn( ObjVar.GetObjectValue() ); //Assign Pawn From Variable Link.
    		ViewRotation = P.GetViewRotation(); //Get View Rotation
    		FloatResult = ViewRotation.Pitch;
    	ObjName="Get Player Pitch"
    4. Continuing on in Kismet, I added a PlayerSpawn and moved the light ontop of it (even though it doesn't really matter where you position them). I created a new Player Spawned event, and created a new Player 0 variable. I then continued in the sequence adding my own custom View Pitch finder action, and set its output to become a Z Float. I then add a Get Location/Rotation node, and set it to a dummy Vector. The Get Location/Rotation would only get the Player X and Y Rotation, NOT the Pitch. Therefor I created a node to retrieve the X and Y values.

    Now here is where it gets tricky. UDK is bugged in some respect because somehow the Set Actor Location Node has its Rotation switch completely messed up and out of order in relationship to the Get Location node (the pitch, the yaw, the roll are all in the wrong spots). If you look closely in the Kismet setup below, you will notice I created a Set Vector Components node and fixed this error by placing them in the spot where they should be. They aren't even labled correctly in order on the Set Actor Location node itself; vectors should at least line up with rotators. My Angle/Z was placed in the X slot, my old angle Y from the player was placed in the new Z slot, and my old angle X was placed in the Z slot. This new vector was plugged into the "Rotation" input, the Spotlight was plugged into the "Target" and the Player was plugged into the "Location."

    I then attached everything together near the end, and added in a Gate to prevent the game from crashing when the player dies. Be sure to set the Death Event and the Player Spawned Event to 0 Max Trigger Counts. There also needs to be a Delay on the Output of the Set Actor Location and then you have it go all the way back to loop to the Get Player Pitch action. This will keep it updating.

    Thank you!

    I seem to recall that it is possible to more easily set the flashlight movement by hard- attaching the spotlight to the weapon socket, assuming the pawn has one...?


      Yes that is actually easy.

      That was the backup plan I had done earlier.

      But for the thing I was creating, the player wasn't supposed to have a weapon .


        In kismet you can make a simple flashlight with a few nodes. I'll give you the UDKC link. I'm not sure they show you how to turn it off though.

        Sorry I didn't completely read what you had done. That wouldn't give you pitch either, sorry.

        That is the one I use though to avoid kismet. I'm pretty sure it avoids the weapon too but I'm not 100% as I never use it without one.


          Thanks for this just spent the last hour doing it.

          This works great and has helped my project alot. And great work from only 2 days.



            Thank you! I originally had a kismet-based workaround for getting the player's pitch ( but it appears to have stopped working in recent versions of UDK. This has saved me tons of hours finding a new fix!