8 Directional Crosshair

Hey guys,

I’ve been running into an issue trying to make an 8 directional crosshair for the sidescroller template. Honestly I’m incredibly lost at this point, as I’ve watched numerous tutorials and tried to do what I thought may work from the SillyGeo sample. Nothing has seemed to work thus far. If someone can just point me in the right direction I could likely figure it out. I want the crosshair to respond to the mouse Y axis, and the right stick Y Axis for a gamepad.

0e72be04602ee8a17ddd4b5e976985f11bbba0b6.jpeg

Thus far I have that, but the crosshair only stays directly in front of the character.

What exactly is an 8 directional crosshair?

I am likely referring to it wrong, but I’m meaning to ask how to make the crosshair be able to aim in all 8 directions on the axis. Like Contra used to be

Sorry, i never played contra. I know, blasphemy right?

Anyways, do you need the crosshair at a fixed distance or wherever your mouse is?

There are couple of threads with this problem. Search for more detailed description.
Anyway this is simplest version:

  • get up vector and forward vector of your character. Normalize both.
  • calculate vector from center of screen (or character) to location where mouse pointer is. Zero its “depth” value ie it should be [x,0,z] or [0,y,z] depending which plane is your screen plane. Then normalize that vector.
  • now calculate dot product of UP and mouse vector, then forward and mouse vector. Both values are cosinus of angle between vectors. No you get one of them and do arcus cosinus to get degrees, then you use other sign to see it its plus or minus that angle from another. That is because dot product gives same angle for right and left sides.

I helped about 4-5 times to solve this problem there are threads discussing it, just search.

Oh and debug every step, for that use “line trace” set its debug line to display for frame or duration.
Check one by one if all vectors are correct. For eg draw, up vector of character (multiply its length by 1000), then stop game draw forward vector. then draw mouse vector make sure its always from character (or screen center) to your mouse (or pad direction). When all vectors are exactly what you want them to be, calculate angles. Its quite common to make vector calculations correct but to have wrong vectors as input, thus making results all wonkyy. For eg if you rotated character by 90 deg (like character setup tutorial says) and you take capsule forward instead of character mesh forward vector, you will get weird results.

Will that work even for the right stick axis on the gamepad?

That you setup in project settings.
I see you need to follow some tutorials first.

Ugh, vector math. The bane of my existence. I REAAALY have to get around to learning this xD

Out of curiousty, doesnt the up and right vector nodes already normalize th output for you?

My non math method of doing this would be binding the change in crosshair location based on the axis input. Basically a branch that checks if the X/Y axis is returning a positive or negative value and repositioning the crosshair appropriately.

Did you ever get this done? I would like to see the blueprint.

I’d think the easiest way is to attach a widget with an offset to the character blueprint. Then using the input values of the mouse/pad move the cursor widgets relative position.