Download

How to make a camera move to where it's looking?

Hello,

I’ve been following this tutorial: https://www.youtube.com/watch?v=FYtLXR4-VZc

Basically, two Camera Components on a Player, one is tied to it and follows it around, the other is a top view that can be moved by moving the mouse on the screen edges.

It works fine but I wanted to expand on it, more specifically, give the top camera more movement abilities. I managed to have it zoom and pan, it was all working good… Except one thing:

When I move my mouse to, say, the top of the screen, the camera will move towards the same direction always, regardless of its rotation. This direction (let’s call it North for simplicity) matches the camera’s forward vector’s, so I suspect that’s why I’m having trouble.

So for example, if I don’t rotate my camera and move my mouse to the top of the screen, the camera will move forward, as expected.

But if I rotate my camera 90 degrees to the left, the “North” is now on my right. And then if I move my mouse up again, the camera will start moving to the right, and not forward, as I would like.

I’ve tried many things, with local offset, setting relative position instead of world position, I’ve tried different things to rotate the camera, nothing has worked.

It’s probably worth mentioning that the camera I’m using is a Camera Component, child of a spring arm, itself child of a pawn. I’ve also tried this with a camera pawn and got the same result.

There must be something I’m doing wrong. Can someone help me with this? What I would like is a camera that always move towards its relative direction. So, regardless of its rotation, a mouse moving to the top of the screen would move the camera forward, always.

Thanks

The tutorial literally has you changing the position via set actor location by multiplying the forward vector with a custom value.

That custom value, or Axis, the way the tutorial does it is only true when the camera doesn’t rotate.

You need to define the axis based on the camera rotation.

Top of screen returns +1 when you look upwards of the screen.

Assume that you rotate the camera and forward vector is now pointing to the bottom of the screen.
Mouse towards the top needs to return -1 instead of +1 for the camera to move the right direction.

cheat it.
take the final vector as the tutorial shows and plug it into the A of a RotateVector node.
plug the camera’s GetWorldRotation into B

The resulting vector should be rotated in the proper direction.

Hi, and thank you for your reply.

The tutorial literally has you changing the position via set actor location by multiplying the forward vector with a custom value.” I don’t get this. The way I understand it, the tutorial has me interpolate between two vectors, but none of them, as far as I know (which is, admittedly, not much), is the forward vector.

I added a RotateVector as you suggested but I got the same result. Here’s what it looks like:

(That’s in the Move Camera function)

Could be you aren’t getting the rotation of the rotated camera.

also has to be before the interp.
That the value that’s into target, rotate it, and feed it as the target.

You should have the forward vector multiplied by the axis if you followed the tutorial. Within a “move” function.

You can also print our the value with a simple print. Just to visually see if it is actually rotating or not.

I might be dumb, but I’ve rewatched the video and I can’t see any mention of the forward vector. I did print its value, and it’s actually changing when I rotate the camera… so this makes even less sense to me now. I am using the correct actor for the camera.

I’ve tried putting the RotateVector before the interpolation but that did not change the outcome. I’m now trying to see where I could add the forward vector in the function, or even redo it to use it.

(I rotate the camera using SetWorldRotation, should I be using something else?)

Well, the tutorial you are following isn’t the best. You’d need more experience to come up with something else.
I have my own solution that works, but it’s not an easy copy paste.

The tutorial here uses world location
https://youtu.be/FYtLXR4-VZc?t=1195

The concept should be the same as this:

Cam Move X/Y is literally +1 -1 defined by the direction the mouse is in.

Up is +1, Down is -1, Right is -1, left is 1.

camera speed is how much that value is scaled by (20 ion my scase).

The values in Make Vector are flipped because logic.
Screen X cardinality (Horizontal) is = actor Y left/right
Screen Y cardinality (Vertical) is = actor X forward/back

The tutorial has a similar make vector, so you should be able to plug something similar in to rotate the vector accordingly.

Also, just to mention it, vinterpto is useless if you are applying the movement in a tick event.

If you ever have problems with RotateVector using GetWorldRotation, i’ve noticed the GetWorldRotation and GetControlRotation nodes sometimes return a very janky, unusable value. This is what I found to make it work better, might help you (replace control rotation with getworldrotation):

… get world rotation returns a normalized value, so what do you mean by Janky / it’s literally not possible since it’s normalized?

Maybe i’m remembering the wrong node, but get control rotation and 1 other have given me values that are impossible to work with, for example when rotating, it might go from 352 to 360 back down to 300 something, while doing a full circle which makes no logical sense. Using the delta method fixed this for me, I just thought I would add a simple thing to try since OP seemed to be having trouble with your method despite it being explained well

Thank you for your help, I really appreciate it. I will experiment with your suggestion in the coming days and see where it takes me. Hopefully I’ll manage to get the result I want.

Well that was quick… I ended up tossing 90% of the tutorial and mixed your stuff with my own knowledge, and that worked PERFECTLY.

Thanks a lot for your help!