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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Moving camera towards right gamepad stick direction

Hi! I'm working on a mobile twin stick shooter and I have been trying to figure out how I could smoothly move my camera a little bit towards the direction I am shooting with my right gamepad stick to create a bigger field of view.

Here's an image of the blueprint as is: alt text Now I was thinking that I must take the axis values and make them into a vector and then somehow add them to the camera location to be able to move it the direction I am shooting, but my attempts have not worked. A friendly hand would be dearly appreciated! :)

Product Version: UE 4.10
camera.png (299.0 kB)
more ▼

asked Feb 13 '16 at 12:30 PM in Blueprint Scripting

avatar image

19 8 8 11

avatar image Mr-Manly Feb 15 '16 at 03:56 PM

Additional info: the camera movement I would like to achieve is very akin to the one they use in Nuclear Throne - https://youtu.be/bVPg2g_enBI So instead of having the camera move towards your mouse position as in Nuclear Throne, I want the same thing to happen using my right stick towards the direction I'm holding it

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

You can use the AddRelativeLocation node of the camera component and move the vector of your axis input.

In the example, FireFoward and FireRight are my InputAxis for the Right stick and then rotated it since the camera is facing down.

alt text

more ▼

answered Feb 17 '16 at 01:10 AM

avatar image

43 5 5 7

avatar image Mr-Manly Feb 17 '16 at 09:32 AM

Hi, thanks for the reply. I am having trouble figuring out how I can reference my players camera component into the player controller. What should I do?

avatar image NecroTheif Feb 17 '16 at 09:37 AM

I don't know exactly how you project is setup but I'm assuming your camera is in your player pawn? If that's the case just get the pawn with the "getControlledPawn" node and cast it to your class of player and then you should be able to get the camera component.

avatar image Mr-Manly Feb 17 '16 at 10:00 AM

Hi again, you are right and I tried casting it and it works! :) But now I have some follow-up questions if you are able to help :)

I got the camera to move in the direction I want but there is no limit, and it just keeps going into infinity. I'd like to add a limit, and I guess I need to use the VectorLength somehow to do that.

The second thing is that it could be cool if I could somehow create a fast but smoother reset when I let go of the right stick. I recorded a video for you to see what I mean: https://youtu.be/Lw94UC2sPAc

Also here's an image of the blueprint right now. alt text

untitled.png (324.9 kB)
avatar image NecroTheif Feb 17 '16 at 01:18 PM

For setting a limit just add a branch before you move the camera forward and of the vector length of the camera's relative location is equal to or above the limit do nothing.

As for making the camera reset smoother but fast just try change the value you multiply the camera's location against. (i.e. Make it smaller to slow it down, -.01 or -.1) it would probably be easier and better if you made a variable for it like "CameraResetSpeed" and multiplied times the delay seconds so as to make it the same speed no matter the computer.

avatar image Mr-Manly Feb 17 '16 at 01:33 PM

Awesome, the camera reset works, and lol what an easy fix :D The only thing left is a weird thing happening with the camera if it hits the limit.

It just gets stuck on that location and does not change if I rotate it any other direction unless I reset the camera

avatar image NecroTheif Feb 17 '16 at 02:29 PM

Oh, sorry. The camera gets stuck because once it reaches the max it doesn't want to move anymore. If you want to have an effect where it still moves in the max you will have to "predict" the new location.

This is actually simple using the "Clamp Vector Size" Node. Just add your Delta Vector to the camera's position to get the prediction then clamp it to your max and then subtract the position to get the new delta that is now clamped.

example: alt text

avatar image Mr-Manly Feb 17 '16 at 02:50 PM

I am sure to be doing something wrong, I'm guessing I am using the wrong Delta Location, because that's the one confusing me :D Here's an image: alt text

hmm.png (273.8 kB)
avatar image NecroTheif Feb 17 '16 at 04:17 PM

Oh, sorry. You need to remove the 2nd Branch (The one for max length) since the clamp node handles that instead (it will set delta location to 0 when at max).

avatar image Mr-Manly Feb 18 '16 at 02:40 PM

It works perfectly now! Thank you for your help, you da man! Have a great day :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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