Move Camera/Pawn by dragging with left click?

Hello. I am having issues with getting my camera right. And I have no idea where should I look into.

What I am trying to achieve:

1) When left click is held down, and dragged towards you - camera moves forwards.

2) When left click is held down, and dragged away from you - camera moves backwards.

I am using the Blank project, the default camera is the kind of “flying 3D camera” I would want to experiment with, so I enabled mouse cursor in it.

Are there any kinds of examples anywhere I can look to make this work?

Hey there,

I’m not at my desk currently so I won’t be able to provide screenshots but the general logic you’ll want is like this:

  1. On the event ‘Left mouse click’,
    grab the location of the mouse.
  2. With a tick function, determine the distance of the current mouse position from the starting position.
  3. Within the same tick, update the location of the camera accordingly.

You’ll need a gate for this. The tick function would enter the gate, the left click would open the gate, and the left click release would close the gate. The gate’s exit would be to determine the distance and update the camera.

The gate would need to start closed as well.

Hello Hidden Master,

It sounds like you want to be able to click and move. There is a top down template that you can look into that has this sort of functionality. You could look through the blueprints and see how it was done. I hope that this information helps.

Example:

Make it a great day

I really appreciate your answer! However I am too green with UE4 and blueprints, it’s hard to figure this one out. Would you be able to provide an screenshot some time? If this is not too much asked.

For now I keep trying and researching to get this to work

Thanks again!

No Rudy, I do not wish to click to move a character.

The “character” is a camera view, with no visible body. It can float around, Blank project is the best starting point for me right now. I created a “default pawn” from it’s blueprint but I don’t wish it to be able to move with WASD keys around, I want the view to move forwards or backwards by dragging with the mouse.

Example: I hold down Left Mouse Button on a a landscape, then pull it towards “myself” and the camera will move the view forwards.

So basically, instead of mouse scroll zoom in out from point where camera looking at, you want to do it with click hold?

If yes, you need to create spring arm, attach camera to it (screenshot top letf), change default spring arm length, rotation and other stuff, as you like it and make code like this

http://puu.sh/qUhpX.jpg

also you might want some boundaries, so you can check current length for it and if you need to swap dirrection of camera movement, you need to multiply value by -1.

Hey thank you for the example :slight_smile: I managed to attach a spring arm and a camera to my pawn, they do work.

Should this blueprint be done as “level blueprint” or inside my pawn “construction script” or “Event Graph” ? I’m sorry if this question sounds dumb, I still haven’t figured out which place to make BPs in UE4. For now I’ll try fiddling with this in “level blueprint”.

Also another silly question: How do I get the 2 boxes on the screenshot which got “Add pin” on them? I got rest of the stuff, but those two are missing :confused:

Its inside pawn. Important note to check out from right mouse button and Mouse Y nodes details “consume input” so you can use same nodes somewhere else if you would need to.

Boxes with x and + is math, green wire stands for float(floating point number) and when you drag it out and type *(for multiply) /(for divide) or other math.

Hey, this is awesome, but is there a method to make this work for the X axis too? I tried copy and pasting the nodes, and replacing Mouse Y to X, and it still wasn’t working.

I cant guess whats wrong with stuff which i cant see. Its should work, this is really simple stuff.
You can put print strings all over the place and track down what doesnt work.

I managed to copy this circuit you showed me, but I am failing to see it’s effect :confused: why though? I put it inside my pawn’s Event Graph.

Also my pawn has “Add default movement bindings” box checked, but if I turn it off then I can’t still move my pawn.

What does that mean, to work for X axis?

I see the problem there, but i would allow you to find it by yourself, as a lesson, so you actually understand whats going on with your code. As a tip, i would say that mouse Y return value is basically how rapidly mouse moves on screen on Y axis.

oops! Is this BP at least correctly setup? I turned off the “Add default movement bindings” from my pawn, but I can’t move at all in-game now. Any suggestion for what tutorial type I should look up to get this thing right? I wish to make my own control bindings to work instead of just WASD. This type of BP should be one of the control methods.

uh oh! I had no clue the number down there in the box would have an effect, I thought it can’t have any effect since there is no connection coming out from the pin next to it :slight_smile:

Also I discovered that I had to go to Project Settings, create an Axis mapping under Input. Then put that instead of “Mouse Y” in the BP.

The effect I am getting is this: When I hold down RMB, the camera starts to move forwards until I let go.

How can I make it so that when I hold down RMB, it doesn’t move the camera forwards or backwards, until I move the mouse up or down?

Move mouse upon on the desk while holding RMB - camera moves forwards
Move mouse down on the desk while holding RMB - camera moves backwards

Either way, I really really appreciate all of this :slight_smile: it has helped me A LOT. I went from not being able to see a custom control - into seeing a change!

Dunno, works for me http://puu.sh/qVw4p.png
http://puu.sh/qVw6m.jpg

Yes. Both axis to work, so not just Y.

Check out Third Person Template, it has camera rotation implemented. But as far as i remember, you want to make spring arm to use controller roation and for actual imput you would use Add Controller Yaw input.

Is there something I can add to the existing blueprint you created to add both mouse axis?

Yes, i told you, controller yaw input, basically copy mouse yaw input from third person template.