Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Camera between player and mouse

Hi I'm trying to make a top-down camera that follows the mouse cursor but without loose sight of the character, so the camera is always between the character and the mouse cursor. Something like Magicka Wizard Wars. Let's say that the center of the screen is the position 0,0 When I move the cursor 20 "units" to the right, I want the camera to move 10 "units" to the right. That way, if the cursor is on the right-top edge of the screen, the player character will be on the left-bottom edge. How do I do that? I know that it's possible to make the character look at the cursor, but I have no idea how to move the camera based on the cursor location. Also, I don't really care if I need to use c++ programming or blueprints, whatever works. Thanks for nay help.

Product Version: UE 4.7
more ▼

asked May 17 '15 at 06:14 AM in Blueprint Scripting

avatar image

11 3 4 4

avatar image _cDub May 17 '15 at 06:24 AM

I haven't messed around with the cursor at all yet, but on a high level I would do something like this: on each frame get the players x/y position and the mouse x/y position. Make sure the Z value is the same when you go to check the distance between those two points. Set the camera to where ever the mid point is [(x1 + x2)/2] [(y1 + y2)/2]. Take the distance that they are apart and move the camera up or down based on that. You will probably need to use some trig and take into account the FOV for that, not sure if blueprints can do sine and cosine.

For a smoother effect, apply a velocity and velocity dampening to the camera instead of just settings its position. I'm not sure if that would have any consequences though.

avatar image Chrystianz May 17 '15 at 09:05 AM

Thanks for your reply. I actually already tried this, but with no success. The node that give the mouse location is something like get Mouse Position Scaled by DPI, I don't know exactly what it means, but it positions the camera in the wrong location.. About smoothing the effect, it's not necessary since it's updated every frame. At last seems smooth enough to me (just wrong positioned).

avatar image _cDub May 17 '15 at 01:54 PM

Did it try to move the camera closer to the origin of the world? If so I think what that does is just get the cursor's screen space coords. So if the cursor is at the top left corner, that node will always return 0,0 no matter where you are in game.

You may have to do a ray trace from the cursor...if that is possible.

avatar image Chrystianz May 17 '15 at 10:52 PM

I put a "print string" and I got just (0,0,0) no matter where my mouse is. I got the values that I want through the "Get Mouse Position" inside the Player Controller Blueprint, but I control my camera through my CharacterBP. Do you know how can I get the communication between them? I couldn't get it working following others posts about that. I guess the fastest way would be passing the mouse position vector from the controllerBP to the CharacterBP

avatar image Erasio May 17 '15 at 08:59 PM

That's actually not the best way of doing it (I mean the "Mouse Position Scaled by DPI").

Could you try the same thing with "Get Hit Result Under Cursor by Objects"? This provides the hit result of a trace from your camera through your mouse onto the environment and therefore provides you with the location your mouse would click.

In my experience that's the best node whenever you want to work with your cursor location in world space.

Cheers :)

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Hey, I finally managed to get it working. Thanks. alt text

magicka camera.png (130.2 kB)
more ▼

answered May 18 '15 at 12:36 AM

avatar image

11 3 4 4

avatar image wiboalux Feb 12 '17 at 03:23 PM

hi chrystianz, i tried you're blueprint but it's doing somethings strange. My character he's always in the center of my screen but when i'm moving my camera, my character is moving also at the opposite of my cursor and i can't move my character with the inputs can you help me pls ?

alt text

alt text

sproblem.png (320.3 kB)
sans titre-5.png (336.6 kB)
avatar image Chrystianz Mar 10 '17 at 05:41 PM

Hi, sorry that I couldn't answer sooner, my computer died and I couldn't buy another at the time. Anyway, that blueprint is only for the camera, you should not bound any movement to it. What I did was use the character that already used the topdown click-to-move scheme and changed only the camera. It shouldn't be anything difficult, but I'll install the UE4 in my new computer and see if anything changed in the latest version of the engine

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question