Download

Mouse-driven movement

Hello

My character is constantly moving forward, but i want to the movement (left/right/up/down) to be mouse driven and smooth, i also want that when there is a left click, my ship goes -90/+90° on the left/right (goes vertical)
How to do that in an easy way, and also make the movement more natural (like the camera doesn’t follow instantly the ship, but is a bit late (like 0.2s of delay)
Anyone can help me figure that out ?

So your ship only moves in the 90 degree angles, and you want to control that via the mouse? If so, what you first need is to detect where the mouse is with regard to your ship. I would do this by using a trace. See here some discussion on that: How do you raytrace the mouse screen position onto a world XY Plane? - UE4 AnswerHub

I have succesfully converted mouse position to a point on the Z=0 plane using a Get Hit Result Under Cursor By Channel node, and placing a large plane mesh at height Z=0… So then use the world location to compute and store a target direction for your ship. I’ll talk about smoothing a bit later.

For the camera following with delay, I would create a custom camera. So drag a camera actor in the world and point it downward. Then create a reference to it in your level blueprint, and call SetViewTarget on your PlayerController and passing that camera actor as parameter. Then every frame, you want to update that camera’s position to approach your ship’s position.

For smoothing, both for smoothly rotating the player’s ship and for smoothing the camera movement, you can call Lerp every tick. There is a node Lerp (Rotator) that you want to call each frame to smoothly change your ship’s rotation to your target rotation. For the camera, use Lerp (Vector). In both cases, lerp between your ship/camera’s current rotation/position and their target rotation/position.