UE4 help? Camera shake by keypress?

Hey, folks!

I’m looking to elicit help in the UE4 engine for a project. Here’s what I’m trying to do:

I’m looking to set up a camera shake, such as being nudged or something, via a keypress. So, for example, the camera is stationary and looking at something, then you press a key on the keyboard, such as the F key, then the camera shakes. I don’t want any effects associated with it beyond camera movement. I don’t want explosions or whatnot… just the camera movement.

Is that possible in UE4? It should be, but I can’t for the life of me figure it out.

I tried contacting the UE4 forums about this but I have not yet received a response about it after more than a day of waiting so any help I can get from you fine people would be wonderful!

Thanks!

I assume you know how to register new action mappings in the project settings. But just in case you don’t:

Then you create a new blueprint with parent class “CameraShake”

Then you go into the newly created blueprint and edit its oscillation settings. I’ll let you figure out what all these things do on your own.

Once you’ve done all that you go into your character blueprint and put in the action input and connect it to a “Play Camera Shake” node. Remember to change the shake class to the CameraShake blueprint you created and connect the Player Character Manager node to the target pin on the Play Camera Shake node.

Thanks so much for this!

I’m lost on the last step–the “character blueprint” part. I see “FirstPersonCharacter > Event Graph” at the top but I have no idea how to get to it.

I should tell you that I’m doing this in “Scifi Hallway” which I downloaded from the UE4 community samples page so I’m not sure if there’s some sort of weird custom thing going on there. Maybe there isn’t even a character controller on this at all, and it’s, like, the editor’s “camera”, as it were.

And I’m a total newb on this so I apologize for any gross stupidity on my part. :wink:

Any further advice on this would be greatly appreciated. Here’s what I’m seeing right now, if that’s any help to you:

I’m probably doing something completely wrong here.

Ah, so you have a blank project with no character blueprint. Alright then, you’ll just have to create your own character blueprint. BTW don’t name your CameraShake blueprint just ‘CameraShake’, otherwise there’ll show up two CameraShake blueprints on the lists and it’ll just be confusing for you :stuck_out_tongue:

First thing you’ll have to do is create a gamemode blueprint. Name it something other than just ‘GameMode’.

Now create a character blueprint. Again, don’t name it just ‘Character’.

Go into your gamemode blueprint and in the details panel change “Default Pawn Class” to the character blueprint you just created.

Then you go into your project settings and in the “Maps and Modes” tab you change Default GameMode to the gamemode blueprint you created earlier.

Keep the project settings open and go into the Input tab, and add all these axis mappings. It’s VERY important that you set the scale values as I have. This is because when you for example want to move forward, you hold the W key and the scale will go up to 1, you feed this scale value into an “Add Movement Input” node in your character blueprint. The Add Movement Input will have the Forward Vector of your character connected into it, so when the scale value is 1, the character will move forward, but when the scale value is -1, the character will move backward. Same thing with all the other movement axis inputs you’ve added. The mouse look Y input has a scale value of -1 because otherwise the mouse look would be inverted (if you need further explanation on this stuff, PM me on Steam).

Now go into your character’s blueprint. Add a camera component, select it and check the “Use Pawn Control Rotation” box in the camera settings on the details panel.

Still in your character blueprint, open the details of the CharacterMovement component, check the three boxes labelled “Orient Rotation To Movement”, “Use Controller Desired Rotation” and “Ignore Base Rotation”.

Now here comes a branching point. I don’t know if you want a flying camera or a first person character. If you want a flying camera, open this spoiler and follow this step. If not, skip down to the next one.

Go into the capsule component inside your Character Blueprint and change the Capsule Half Height to 34.

Then back to the character movement component. Change the Gravity Scale setting to 0, and in the “Character Movement: Flying” change the Braking Deceleration Flying to 2048 (or whatever you want the deceleration to be), and change “Default Land Movement Mode” to Flying.

This step is if you want a First Person character moving on the ground. If you already did the flying camera step, just skip this one.

Go into the character blueprint and move it up the Z-axis to where you want the eye height to be.

Now go into the Event Graph of your character blueprint and add all these nodes (you right click to open up a search box with all the nodes). The gray comments are unneeded, I just add them to tidy up a bit. There’s a bit of explanation on how to find them all below.

The blue ‘Camera’ nodes can be added just by dragging the camera component from the component list into the graph. You can drag off the blue pin (marked with a green box) from the Camera node and it’ll open a search box for you with things that can be added, from there you can easily add the “Get Forward/Right Vector”. Instead of a “Get Up Vector” connected to a Camera node, I connected a “Get Actor Up Vector” to the FlyUpDown movement input. This is because the Forward and Right vectors should be relative to the camera’s rotation (this means that for example the forward vector will be in front of the camera) while the Up vector should be absolute (which means it’ll always go up, if it was relative to the camera’s rotation it would be depending on the camera’s upside, so for example if the camera was pointing down, the upside would be directly in front of you, so the camera wouldn’t fly up but rather go forward if that makes any sense).
If you can’t find some of the nodes, turn off Context Sensitive Search when you search for a node by right clicking (the Play Camera Shake node doesn’t show up otherwise).

Need help or something explained you can PM me on Steamo. If it’s too daunting like this, I could make you a video or something.

That worked out great! Thank you so much, Jack Freeman! Here! Have some Naughty By Nature by the Muppets:

youtube.com/watch?v=mG8yRXdIcZU

:thumbsup:

Founded in 2004, Leakfree.org became one of the first online communities dedicated to Valve’s Source engine development. It is more famously known for the formation of Black Mesa: Source under the 'Leakfree Modification Team' handle in September 2004.