2.5D Camera mouselook


I want to create a mouselook for the sidescroller template which should work something like this:

Anybody have an idea how to do it?


You may have to take into account the player’s resolution if for some reason the pointer can leave the bounds of the screen, but it seems relatively easy to do without error. Here’s the thoughts off the top of my head.

Make it so the camera targets the exact center point between the pointer and the character. This will make it so if the pointer is on the character, the camera will also be on the character and when the pointer is on the edge of the screen it will create the exact image you see.

I’m not sure all the blueprint nodes that would handle that, but you’ll want to

  1. save the player’s location and pointer location every tick.
  2. calculate the distance between them.
  3. divide that distance by 2.
  4. move the camera to that location.

Thanks Quartaroy, but I forgot to mention that I’m a total noob at blueprints, so I kinda confused and don’t know how to do it exactly.

Do you think it is possible to attach mouse X and Y parameters to a math equation and the results of that will become Camera Y and Z parameters, while the camera stays parented to the character? I’ve tried to do it, but failed - don’t know which nodes to use etc.

I’ll see if I can give you a screenshot when I figure it out. Worked on it a few days ago, was having issues, as it has some bugs with the way I thought of doing it. The camera works to the right fine, but doesn’t like going left. My math seems to be off a little.

Novice here too, but I was able to get some control like this using the Hud BP, to get the screen position of characters and the mouse.

For the mouse, first you need the get a player controller node, then use the get mouse position node.

For characters, I used the Project node.

You might link a dummy to the player, and add the screen XY coordinates to it’s 3DVector.

I finished this out of curiosity, many gotchas happened along the way.
For 3d side scroll, the effect is not as good, maybe zoom out further and limit scope of range is better.
But for 2D side scroll it seems to work pretty well.

So some hints before I decide to put the whole project up or not.

  1. I did this with almost 99% graph in playercontroller, the only other thing I did to my side scroll pawn is adding an offset(scene component) as parent of spring arm.
    I just show mouse cursor, HUD could be used to draw a bit map at cursor location if I continue doing this, but I don’t see why I should.
    Set offset rotation to absolute, and create an interface function to accept a world location.

  2. the gotchas are as following:

    • mouse location are (-1,-1) if out of screen from anywhere.
    • coordinate you got from “ConvertMouseLocationToWorldSpace” is on a fixed plane, I assume it’s where the camera’s near clipping plane is.
    • you need to scale that vector so it lays on the same plane your character’s movement plane is.
    • you need to disable collision test in case the collision sends your camera flying( at least before you have a proper level designed for this type of 2d mouse look.)
  3. extra stuff to consider

    • since screen resolution is not fixed aspect ratio, so you need to calculate your limit on the fly.
    • character distance from screen edge needs to be around 3 times the capsule size, otherwise it goes out of screen easily.(especially if your camera spring arm is not aimed at character straight on.)
    • you need to check for if cursor is right on the actor pivot(vector length zero), if cursor is with in valid range
      (screen resolution- 3*capsule size, that’s around 1.5 cap size border so your char don’t go off screen)
    • if it’s outside of valid range, you need to calculate a proper vector so it place the offset on the edge of valid range.( so your camera movement is smooth in or out of valid range)
  4. math stuff

    • half point between 2 world position = (posA + posB)/2
    • arbitrary point between 2 world position = (posB - posA)*scalar + posA, where if scalar is 0, result is posA, 1 then result is posB.
    • scalar = 1/max( abs(mouseX-actorX)/resolutionX, abs(mouseY-actorY)/resolutionY), where resolution x/y is the reduced amount.

I know posting screenshots and projects would help people faster, but I start to wonder if that’s actually helping the community.
I really want there to be a proper discussion and then people come up with different or even better solutions.
It’s along the way you build solutions makes your understand how UE4 works, not just follow and memorize what to do in certain situation.

no one reporting success yet?? I’m gonna be a sad panda. :frowning:
maybe I should record a video of mine running.

A Video would be nice to see how it works for you.In my Other Post for 3D Sidescroller with Mouse click the Workaround doenst work so well…

guess I’ll do that tonight combined with your spawn on click location.

here is the video, it might still be processing, but after that’s done should be viewable.
spawning takes something like 2 minutes to do after the mouse look is done properly previously.


Come on guys, all the info needed to create all these is already in my previous post.

I just tried to get it like yours but without the workaround of invisible Cube at my players mesh i cant get anything to work. it quiet hard and i tried many different things.
Is it possible that you show us(me) the Blueprint you have done?

Thanks to chinty reminds me.
I guess posting results still better than nothing.

So let’s begin on the pawn setup, it quite easy really, as you need to have a offset scene component that have absolute rotation set to 0,0,0.

And then have an interface function to set offset’s world location(so you don’t have to use CastTo).

Here is the overview of my player controller class, I commented the block in number so you can refer back to this chart in case you are unsure which block goes to where.

Simple things to get started, on begin play, gets player capsule half height, and use it as our screen border buffer, 3 is just a number I picked, you can use whatever you like.
Spawn cube is just a simple call, as long as you calculation mouse world position right.

Now first block, here we try to convert mouse screen space location into world space.
However, the converted location is on somewhere close to near clipping plane of your camera, so that’s not good.
But the call also provided a world direction, that offers us a base to extend our mouse location to where our pawn’s action plane is.
(ps. you can cheap it out and make actor’s action plan is on say x=0, but setup this up properly will cause less headache.)
For spawning things correctly, you have to calculate this right.

2 and 3 is to save some important 2d vector for later use, base on our capHeight variable, we need to reduce the distance camera can travel.
and to calculate valid range, we need to save both max screen resolution minus border and mouse to actor vector.
(Note, Max2DVec should never really change, so it can be set during the begin play event, but in case you have adjustable screen size, this is for you.)

First branch node checks if mouse cursor is directly on character pivot, this would prevent divide by zero error and all other craziness just in case.

If we indeed have cursor directly on top of character pivot, here is number 4 block do, place offset component to where the character is.

  1. is to check whether or not cursor is with in valid range, which means for 2D x and y distance from mouse to actor should both be smaller than the max2DVec we saved.

  2. if mouse cursor is in valid range, just apply half point between mouse world location and actor world location to offset scene component.

  3. if one of the x, y value exceeded our valid range, we than have to calculate and shrink the vector to the closest point on valid range border where it intersects our actorToMouse vector.
    The calculation is based on which one of x and y exceed most, use it as base to shrink our half point vector.

There you go, enjoy this simple graph. I’m sure people would have better way to organize it with sequence.
Hopefully you can extend this and make much more exciting input features.

Thanks PenguinTD, very helpful little tutorial, i will use this tomorrow. I hope you have been a happy panda :slight_smile:

Hi, sorry if this is a silly question, but I cannot figure out how to get this “Event set Camera offset” to show up. I will keep digging in the mean time, but any help would be appreciated.


Nevermind, I got that all figure out, just took a little digging. For the most part it works well now, but there are a few areas on the screen that cause the camera to shake really fast, then I move the mouse and it’s okay again. I think it has to do with the mouse world position translating to screen space. I will do more testing. And idea’s would be great. Cheers.

I’ve been trying my best to achieve the same results. I’m unable to find “actor to mouse” and “max2dvec”. The “Set camera offset” is also throwing me for a loop. I know this thread is old but has anyone tried this in the newer versions of the engine? Thanks!

Hi, really nice tutorial, but I have an issue. I can’t find your Camera offsets event and setter. Will you be able to explain how to use them, or probably send a file with them?