Newb question: Analog input to screen coordinates

Hello everyone,

Since the free release of UE4 I’ve been playing around with the engine. Amazing stuff!

Anyway, to the point. I’m working on an on-rails shooter as a teaching example, and I’ve run into a snag. The desired behavior is that the analog stick maps directly to a crosshair on the screen. I was initially surprised to find out that the analog sticks on the gamepad have a constant radius, thus the corner position (top right) isn’t (1,1), but actually (0.7…,0.7…). I guess I shouldn’t be entirely surprised now that I think about it, since they’re, in fact, analog inputs. Anyhow, I need to convert the position of the sticks in the circle to an onscreen coordinate like so:

405f148e432307f78c880f08cf936371f318cd11.jpeg

So I started working on the trigonometry to convert the analog position to on-screen position in its own blueprint, but before I go any further I was wondering if maybe there’s an easy way to do this, or maybe there’s some method that I’m not aware of that can do this already in an efficient manner. Since I’ll be running this conversion on every tick, I don’t want it to be taxing.

Any thoughts would be appreciated.

Thanks!

Hi

So are you using a custom crosshair or the one in the HUD?

I’m very new at this, so correct me if i misunderstood your question.

It’s a UMG blueprint widget that I placed on the viewport.

I’m sure there is a ‘map’ node of some description that will map one range to another

I’ll look around, but the problem is that it isn’t a linear interpolation between ranges, so a range-to-range wouldn’t work. That is, in fact, what I have in the current behavior.

don’t really understand your problem completely but the engine handles most cases for you

have you tried setting up the analog stick in the project settings (find it under settings tab at top of viewport) under input then add an input event for whatever you are trying to access?

I’d also suggest a google search for Unreal Engine 4 then the topic or whatever you are trying to accomplish, I’m pretty sure this has been handled before.
probably something like crosshairs &/or scope (sniper) would be a good search to start with.

also always check this if having problems: .unrealengine.com/latest/INT/

I hope this doesn’t come off as rude, but your post is not very helpful or pertinent to the question here.

Yes, I’ve hooked up the input events; and yes, I’m handling them correctly. This was all explained in my first post, i’m well past that point.

I’ve googled this a bunch. That’s the first thing I did. Since I couldn’t find anything helpful, I thought I’d ask here. Your answer amounts to ‘Let me google that for you’, which is less than helpful.

In case it isn’t clear: This is not a first person scenario. I simply want to map the analog stick to a simple cursor, much like a mouse does. So the scope/sniper suggestion isn’t applicable either.

Lastly, you’re giving me what is, at best, a guess as to wether the engine provides this out of the box, but nothing else. This is also not helpful at all.

I apologize, I’m not trying to be rude or offensive, but your post is just remarkably unhelpful and off-topic.

ok, sorry for trying to be helpful

some links might be helpful then:
https://answers.unrealengine.com/questions/91721/how-to-move-mouse-cursor-with-gamepad-stick.html

from here: https://www.google.com/?gws_rd=ssl#q=unreal+engine+4+cursor+controlled+by+gamepad

if not the same situation as using the controller stick then it should be similar just setup your input to analog controller as I mentioned above and set it to .1 etc. whatever you need then proceed from there.

good luck w/ teaching

sigh… i’m closing this thread… None of this is going anywhere

For the record, I had seen that link before as well.

I’ll restate my situation: I have no problems in using analog input values for the crosshair. My problem is with converting a coordinates limited in a circle (the analog stick movement) to a rectangle (the screen). I know EXACTLY how to do the conversion using BASIC trigonometry and Euclidean Geometry. I already have a blueprint that can do it, but I wonder if there is a built-in FUNCTION that can do it.

Ayretek, I appreciate you trying to help, but I don’t think you understand at all what I’m asking. So unless you actually have a clear idea of what it is that I’m asking, I’d ask that you just please move on, as it’s just creating confusion and derailing the conversation.

So the question, again, is: Is there a function that does this already? Yes or no? I don’t need guesses or links.

I know you labeled this as a noob question, but in reality it is not as simple as it may seem to get the behavior you are looking for. Using a Map Range (float) node with custom calculation for the inputs will get you pretty close to what you need, but is probably not be the ideal solution.

I have only seen a couple other similar questions on this topic in my here, so it may take longer to get the ideal response. But don’t give up! :slight_smile:

p.s. If I can find the links to the similar questions again I will post them up for you!

Fantastique! Thank you sir, this is definitely a step in the right direction.

Apologies to all… it just gets frustrating when you get can’t get your point across.

Well the EASY way is just to map-range the values such that, when the stick is tilted toward the corner, it JUST reaches it, and then use and Min nodes to clamp the other values inside the box (that is to say, visualize the stick as moving the cursor in a circle which exactly encompasses all 4 corners of the screen). The problem with this method is it means that for a standard up/down movement, the cursor will reach the screen’s edge before the stick is pushed all the way to maximum; the advantage is it means the stick’s movements will interpolate correctly (i.e. a horizontal movement of the stick will always correspond to a horizontal movement of the cursor, it won’t bow inward toward center screen when you move directly from up-left to up-right).

The other option is The Complicated Math Way:

First you have to make a vector from the two input axes. This vector will have a length value between 0 and 1.

Second, you calculate the angle difference between this vector and some arbitrary other vector (say a unit vector pointing right.

Then you calculate, based on the dimensions of the viewport, what the distance is from center screen to the edge of the screen AT THAT ANGLE (again, assuming that 0° is equal to directly right).

Then you use a map range node to map the 0-1 length range of the unit input vector to a 0-X range where X is the distance from step 3 (so the stick is always at the edge of the screen at full tilt).

THEN, using the screen dimensions again, you reconvert the distance and angle into screen coordinates, which is where you put the cursor.

That’s the best way I can think of to do it, though getting the cursor to land directly in the corners will still be more difficult than it probably needs to be (since the corners are almost certainly not at 45° angles from center screen on a modern computer’s viewport size).

Yea, that makes perfect sense. That’s very much along the lines of what I was thinking of doing (the second option).

I put something together based on this: http://stackoverflow.com/questions/1621831/how-can-i-convert-coordinates-on-a-square-to-coordinates-on-a-circle

I haven’t been able to test it yet, but it should do the trick. It’s just a LOT of math for every tick. It’s relatively simple math if I keep it in the Euclidean geometry rather than trig (using vector lengths/analogous triangles, rather than using the angles). This should make it a taaaad cheaper to compute. Maybe it is what it is!

You know what? This might just be good enough… I’ll definitely give this a shot tonight. It somehow never occurred to me to place the circle OUTSIDE of the rectangle, like you mentioned. That’s pretty clever!