So I’m currently attempting to setup a player entity for use in a first person perspective game environment and I’m running into some issues. I’ve managed to figure out how to create the WASD controls but trying to create the mouse-look controls is giving me quite a bit of trouble. I can make it look around a single axis well enough but once I add another axis the camera starts to rotate into unnatural viewing angles as you look around and looking around with the mouse doesn’t affect the direction the player entity is facing either which is also quite jarring. For instance, you look left and try to move forward only to realize that you’re now strafing to the right and not going forward. all that happens is the direction you’re looking at changes as if all you did was turn your head and not your body. Has anyone figured out a way to actually create standard FPV controls yet? I’m sure I could figure it out using the flowgraph but I’m avoiding it since it’s going to be phased out and am attempting to use the script canvas instead.
Thank you! I’m going to have to do some studying though, I’ve never actually done coding before so I’m not even really familiar with any coding programs. That said however, if it’s something I need to learn then I’m willing to learn it. I was just hoping that somebody maybe figured out how to do it using the script canvas already since I’m a very visual person.
Although this is not written by me nor am I an expert at C++, I was able to follow this tutorial to achieve a generic FPS movement with mouse+WASD.
It’s a series going from movement to cursor control.
I’ve used the following setup to quickly test the idea and it appears to be working:
I connected the input to a Get World Transform -> Get Columns
I took column 1 for forward (in my first message I got the columns for forward and right mixed up). To get a consistent speed independent of the frame rate I used a Tick Delta and a Multiply. The number in the Multiply is the speed in meters/s and I use that number to multiply it to the vector I got from column 1. This gives us the speed vector.
I could’ve use a separate Get Translation node to get the position but the position is already available in column 3. Add the position to the speed vector and finally set the result using a Set World Translation.
Just noticed in the screen grab I use local instead of world translation. It doesn’t matter in this simple example, but will matter once you start using hierarchies.
You can parent the camera to the player entity and setup your controls to influence the player entity. Because the camera is parented to the player it will rotate and follow the player. Place the camera near the head to get a first person perspective.
First off, thank you for the reply, secondly, what would you use to get the columns to refer to the vectors that you mentioned? After doing as you suggested I actually got no noticeable result.
Perhaps I should state that the results I have been able to attain on my own so far came as the result of setting up an input component that then is referenced in the script canvas to enable WASD and mouse-look and for the mouse-look the only script node I’ve found that allows me to manipulate the camera just by moving my mouse is the “rotate around x (and z) axis” node. I just wish that the player entity would rotate with it to allow the mouse-look to dictate the forward movement direction.
Thank you again for the help! I actually got a result this time though it still isn’t what I’m looking for. For some reason using that setup moves the entity forward no matter what direction I move my mouse in rather than just rotating the camera and entity to face wherever the mouse moves.
In the attached image, the two inputs at the top are where my WASD controls are coming in from, below is where I attempted to implement your idea for the mouselook. Sorry if I’m just not getting something but I really do appreciate your assistance with this!
I’ve been experimenting a bit with script canvas myself and I quite enjoyed it. I think I may have gone a little overboard. In the attachment, I’m posting my script and input bindings file.
Parent the camera to the player entity. In the script I’ve put the various variables below in the blue frame. Change player and camera entity variable there to the ones you have setup and it should hopefully work. There are also other constants you can experiment with (invert mouse, mouse sensitivity, movement speeds, limit look up/down angle)
wasd keys is for strafing
mouse to change direction & look up and down.
shift to run
If you have questions feel free to ask.
6587-movement.zip (212 KB)movement.zip