Hello
I want to control my character forward movement (run) with “w” pressed on my keyboard and at the same time i want to control direction of the run using mouse position on screen. Any ideas how to setup blueprints for that?
Thanks for your quick answer, but unfortunately I don’t have this “get turn” function, not sure what is it
Unfortunately, it’s not working
But i was able to do sth like this. I’m not sure why he is changing speed and sliding on the ground!
Here is a video: TowardsMousePosition - YouTube
Unfortunately, it’s not working
but i’ve posted answer above, maybe you have an idea
Yeah sorry, Turn is an Axis Mapping for Mouse X, you can add it in Project Settings Input.
heres a example of how this could be done.
first for the forward W movement. for this i used a axis event such as seen in the third person example. you use the input event (setup in the project settings) and then you get the actor forward vector and connect it to a add movement input node very simple.
for the next part i provided a few options.
first is if you just want to have the character turn when the mouse is moved (yellow comment) and it not to be based on the mouse cursors location. for that instance you simply use another input axis event and the add controller yaw to turn left and right.
the second option (reddish comment) which is what it sounds like you want will require you to get the mouses position in relation to the players screen then do some math. to begin we need to get either the screen resolution or the viewport size, i went with viewport so we get the player controller then get viewport size. next we want to tell if the mouse is on the left or right of the screen so we divide the viewport X by two. we then get the mouse location and subtract from it the viewport half size. this will give us a result that is either below or above zero (you could also just compare the screen half size to the mouse position). this tells us if we need to add a positive or negative value to the control rotation.
i went a step farther here and instead of having a -1 or 1 value i scaled the value based on how far from the center of the screen the mouse was. the results in adding value between -1 and 1 so it could be 0, or 0.6, or -0.3, etc. to accomplish this i just normalized the mouse position to between 0 and screen half size, so if mouse is at 1920(full right on screen) then the value will be 1, if mouse at 480 then the value will be -0.5, given a 1080p screen.