How to move a custom crosshair up/down based on virtual joystick movement


I have a custom cross hair added to a hud in a 3rd person template. I am not sure how to move the cross hair up/down based on when the virtual joystick is moved up or down. hoping some one can shed some light. Thanks

Easiest solution would be to do it in the Pawn class or in PlayerController class if you do not need a Pawn.

Add an axis binding for the joystick Left or Right stick vertical axis that is supposed to move the cross hair up or down. Lets name it ‘MoveCorsshairVertical’

Now lets create float variable named CrosshairOffset that defaults to 0.

After that in your Pawn or Controller blueprint, add an event ‘Event MoveCrosshairVertical’. Wire it up so that when this event fires, it updates the CrossHairOffset variable with the axis value. You will need to multiply it by a scaling factor to make sure it changes in the proper steps. You will also need to use a clamp or a combo of min and max nodes to make sure it does not go out of screen.

Now when you are going to draw the crosshair from the HUD, get a reference to your Controller or Pawn (depending on where you created the CrosshairOffset variable). Cast it to the proper class. Then get the value of CrosshairOffset. Use this to control where you draw the crosshair.

This works amazingly for what I need as well! Thank you!

How do I get a reference to a pawn?

This is an older question, but I see that others are coming across this like myself.

The way I did this was to open my HUD blueprint, and use a “Event Receive Draw HUD” node. That get’s fired very quickly and is better suited to this job then the event tick, however could be used here as well if you wanted that.

Add a “Get Player Controller” node, and from that, “Get Mouse Position”. Those two will get you the current mouse position every HUD Draw call, without the need to cast to anything.

From there, just feed the numbers into a “Draw Texture Simple”.

P.S. Add finterps for a good time. :slight_smile: