God Game camera template - which can rotate, pitch up/down, drag to move in 3D space?

Hi. How come nobody is playing around with God Game style cameras :(? There’s almost no resources for that. I have spent past 4 days figuring UE4 out, but can’t get my camera right how I wish it to be. I couldn’t get drag to move work either, with help from another user I could make it so that when I hold down mouse button, it will automatically start “driving the camera” forwards, but that’s not what I have in mind.

So I thought maybe someone wants to help to create such a starting point for members of the community? I have created a video which demostrates the type of camera in game called “Black and White 1”

Camera goals:

  1. LMB + Drag the mouse on any surface to move the camera around in the world.
  2. MMB - scroll wheel - zoom in and out
  3. MMB + Click and hold, then move mouse left or right - to rotate the camera around the cursor
  4. MMB + Click and hold, then move mouse up or down - to pitch the camera view

You could get the mouse cursor position from the player controller. Then you could use ‘on EventTick’ with a condition which checks for a held down button. If it finds you are holding down a button you can check the new mouse cursor position with respect to the previous mouse cursor position (The difference between the two) and move the camera appropriately. This method should work for your goals 1, 2, 4. For goal #3 you just need a scroll event which moves the camera closer or further from the ground in its current forward facing direction.

For example, if a camera was facing the +X direction and you wished to zoom in you would add n to the X location and n to the Z location. If you wish to zoom to where the mouse cursor is, it requires some more complicated math.

Hopefully I helped!

Thank you Mellark for these instructions, without your comment I probably would of lost all hope. I really want to get into the game with these camera controls, but it is really difficult for a complete beginner as myself. I googled what I could find, learned a tiny bit of variables - but feeling lost again.

Get the mouse position.


Is LMB being held down?


– this is what I got for now. Am I on the right path…? I can’t imagine how can I fulfill your further instructions on this, could I get some assistance please

You are starting to get the right idea, but still a little bit off. My first pointer is in your second screenshot you have that set node feeding into the condition of your branch. I’m not entirely sure if this could cause unexpected behaviour or not and so I would advise just creating a separate get node for ‘Is LMB Down’ and plugging that into the branch node.

You have the right idea with the pressed and released plugs of the ‘Left Mouse Button’ node, but aren’t quite using them the way I described above. My suggestion would be to use ‘Get Mouse Position’ after you know the left mouse button has been clicked. Store this position into a variable called something like ‘Previous Mouse Position’. Then on event tick you first want to check whether the button is still held down which you have done, but then you want to compare the current mouse position with the ‘Previous Mouse Position’ variable. If the two have different values then you know the mouse has moved and if you subtract the two you know by how much and in which direction it has moved. Using this information you could use the camera however you like. Some games like to move the camera in the opposite direction and some like to move it in the same direction and so its really up to you on how you want to implement this portion.

The last step would be to reset ‘Previous Mouse Position’ to the current mouse position after you update the camera.

An example of this would be something like this:

When you hold down LMB
‘Previous mouse Position’ = 6
‘Current Position’ = 0

When you move the mouse by 2 units
‘Previous mouse Position’ = 6
‘Current Position’ = 8

After camera update
‘Previous mouse Position’ = 8
‘Current Position’ = 8

You move the mouse back 3 units
‘Previous mouse Position’ = 8
‘Current Position’ = 5

After camera update
‘Previous mouse Position’ = 5
‘Current Position’ = 5

You release LMB
‘Previous mouse Position’ = 0
‘Current Position’ = 0

Hopefully that helps get you going in the right direction. The last thing I will say is this type of code is generally better suited to the player controller rather than the pawn class itself. However if its working there’s no point in moving it over now. Just for future projects! :slight_smile:

Thank you Mellark for the breakdown and letting me to use my brain :slight_smile: I never was a programmer or anything like that, so it’s super stressful for my brain to figure these bits out.

I am having trouble figuring out this step (physically, I don’t know which nodes I have to create in Blueprint editor to continue):

“Then on event tick you first want to check whether the button is still held down which you have done, but then you want to compare the current mouse position with the ‘Previous Mouse Position’ variable. If the two have different values then you know the mouse has moved and if you subtract the two you know by how much and in which direction it has moved.”

How do I create this comparison? :confused:

This is what I have for now as a single BP, I moved it inside PlayerController as you suggested.


Did I do this right? As I understand, I now have the “set previous mouse position” value as boolean. Which means I can use it somewhere else as Get. brain explodes - I honestly have no clue what to do next :C

Update again :slight_smile: I got some stuff moving now. I can drag and move the camera, will post blueprint at a later time when I get the stuff actually to work.

Also I did not use this blueprint below for anything yet. Maybe when some new cells make connections in my brain, I can find it a use :smiley:


Update…

Is this right?

This is what I have right now

Needed something like this myself but for a skill tree system. The following looks messy but works and should be suitable for your first task.

YouTube example

Second Example, works on landscapes too.

Hey, thanks for the help I really really appreciate the examples :)! I will try them out at one point or try to connect it with my existing stuff that I have now and see what happens.

For now I started to follow a long tutorial series on making a RTS game. The camera results are not exactly what I wanted, but they do similar things (for now). I have rotate and pitch up/down which works with MMB - but currently it only does that around the pawn which is controlled with WASD keys (and I have not yet finished the tut).

! My pawn is a Box shape, the camera follows it while I press WASD. Is it possible to make the pawn become “the cursor” ? :slight_smile: and then when I rotate, it does that around the pawn. But I mean can it become an actual cursor, which interacts with everything in the game?

– The tut where I learned lots of new things about UE4, it teaches how to setup directory for blueprints and other stuff etc. so very detailed.

You can change that box into a hand mesh or what ever you feel you need in the future, keeping it as a place holder for the time being.

If you want to rotate around the box for the time being. This may get you going. I don’t have rotate in my game so this is a quick hack. I’ve added a sphere to the pawn class also and rotate the camera around it.

Example Video (if its not there yet it will be in 2-3 mins)

nice work buddy , can i download this project for learning ? thx anyway !