How to Turn a Vehicle With the Mouse

I’m working with a small team on a vehicle-based third person shooter. Right now we’re prototyping some basic vehicle movements, and we’re trying to get the sedan template Blueprint to turn via left and right movement with the mouse instead of the standard A and D keys (think Halo PC-style vehicle controls). We’d also like to be able to move the camera up and down during gameplay via up and down movement on the mouse. In other words, we want to keep the camera locked to the sedan on the X-axis but have the mouse rotate it and the sedan together, while simultaneously having the camera unlocked and free to look up or down on the Y-axis (or should I say Z-axis?) without affecting vehicle movement.

I have some programming experience and understand the logic of it pretty well, but I’m pretty new to Blueprint and don’t know all the various options that might allow me to achieve this. Any help would be greatly appreciated.

Before anything will work, make sure you’ve got your keys and mouse bound to your own custom Input functions. From the main editor, go to Edit → Project Settings… Jump half-way down the list to the Input settings… Action mappings are for single-shot type events like firing a weapon or doing a jump. Axis mappings are used when you want a constant stream of data, even a steady stream of zeros when you’re not steering at the moment. Whatever you put here for a name of those bindings will become available in your blueprints. For example, you could make a binding called “Camera_Pitch” and add a new item set to “MouseY” to tell your blueprint to move your camera up and down when the mouse does, just not side to side when turning. There’s a couple good vids floating around if you need more help here.

Next part would depend a lot on whether or not you have a player controller or are messing around right in the pawn blueprint, and if you’re driving character movement or using physics sims, etc etc. So I can’t tell ya every possible way to make the steering happen, but I’m assuming it had steering already and you’re just trying to connect it up in another fashion. So the important part there is to right-click in your graph, type ‘axis’ and this will jump you down to a list of all your custom bindings. Icon is a black arrow on a white diamond (not the green functions to read their values). Clicking one will drop a new event for you - called for example “InputAxis Camera_Pitch” - with a float output of whatever value those axes are sending. You may choose to supply negative input thru a second keybind scaled by “-1”, say to have A and D fed to the same binding. For mouse movement, you don’t do this. You might also want to scale the output up, or do some other math on it - but basically that can drive either steering or camera controls.

If the camera is a component on your vehicle, you can drag it out of the variables list and “get” a link to that in your blueprint directly. Pull a string off it in order to find what options you have for giving it a twist or asking it what its orientation is at any moment. Those options are hidden if you just right-click to get a basic context window. The “Get Right Vector” node it provides would be handy to you because if you multiply a rotation (driven by your mouse) by that then it will act like a mask and zero out and roll and yaw you don’t want included.

That should get you started … If you’re a programmer, no worries - it’s mostly all in there. The only difference, once you get the hang of it, is that now you can code in cursive. LOL

Hello ,

U will need to make two Blue Prints. The First one Will be of type Character and it will contain a Camera parented by a Spring Arm parented by your Sedan Mesh as shown below.

15286-components.png

Set the Target Arm Length under Camera in the Details menu to the distance u want the camera to be from the Sedan and set the Use Controller View Rotation to true under Camera Settings.

Place the Spring Arm where u want the camera to be locked onto (i.e. Center of the vehicle).

Now you want to create 2 Bindings for your mouse inside your Project Settings like the ones in the photo.

(Look X and Look Y)

Now create a Blue Print of type PlayerController. And inside the Event Graph you will place both your input nodes and add the pitch input for Y and add Yaw Input for X as shown in the photo below.

I hope this helps at least get you on the right track! If you need any further help with this just let me know!

[Resolved]

Your welcome i am glad you were able to get everything work as you wanted :slight_smile:

I managed to figure it out, but I appreciate the in-depth replies. I ended up using a modified version of the third-person character controller (using a static placeholder mesh instead of the animated human mesh) instead of the sedan to build a custom controller, and from there, getting it to shoot projectiles where the camera was pointed was easy.

Thanks again!

I’m not sure how to mark this question as answered (if it wasn’t obvious, I’m very new to UE4 and AnswerHub), so I guess if a moderator sees this, you can go ahead and close it.