Make a HUD Icon Point at a target

I’m trying to create a HUD arrow that points from the player to an enemy. I’m doing a line trace from the forward vector of my player to the forward vector of my enemy. I’m then using this to drive the angle of a HUD image. This is ALMOST working, but the left and right values are inverted so when the enemy is on my left, the arrow points right and vice versa. I thought I could just flip the Y-axis of the image by changing the image size Y to -64 but this sadly inverts the vertical axis. The angle is a combined value, so there’s no way I can figure how to invert only the horizontal.
Any ideas?

Oh darn. I just realized this is working less well than I thought. Now that I’ve driven around the enemy more, I’ve discovered that the arrow is not updating properly at all. For example:

I was wanting it to always point in the direction of the enemy bike, but when I move to the side of the enemy and then aim forward, it’s not pointing at it.
Any ideas on how to fix this?

Is this for a pure 2d widget? Also, the ‘bikes’ look awesome!


If your arrow points up by default, the +90 should be -90 instead, most likely. fingers crossed

Nicked it from here:

https://answers.unrealengine.com/questions/1008381/get-angle-between-actors.html

3 Likes

Hey this is awesome! Great concept and so much I can do with this. just a couple issues. I was hoping you might be willing to give some insight.

First and foremost, I have this setup EXACTLY how you have it above. when moving about, the arrow is not static like it is on your character. I mean to say, yes, it rotates and faces the objective point, but when I move my character around, the icon physically moves also. for example, if I move my player left, the icon swings around on the screen to the left, and the same for whatever other direction. I though this simply a case of it was placed incorrectly in the widget, so I moved the image around in the WBP to see if I could straighten it out. doesn’t seem to be the case.

Played with the location of the widget component in the character, and it repeats the behavior, just in a different location.

I should also note, I am not intending for it to be exactly on top of the character as you have it, but closer to the minimap at the top of the screen. Though, when I do place it on top of the char, it still behaves as I have described.

I’d appreciate any feedback on what I’m missing here. I’m sure it is very simple! :rofl:

1 Like

I wouldn’t use a widget component for this then.

  • the arrow:

image

  • the script in the player:

Create the widget on Begin Play (or make it a part of the minimap?) - set the location, size. The rest stays the same. It shows the direction from the char to the blue box:

This method may break at great distances knowing that projection node.

Hey that’s perfect! Thank you so much!!!

This is working great but if I may, just one more quick brain pick. I don’t want this running all the time, only when there is an active quest. to do this, i created a quest marker that spawns when a quest is active. its the same exact thing like what you have in your videos, the only difference is it is created at runtime.

Also, I am creating the widget when the quest begins.

I get the following error:

I thought maybe I need to spawn the widget and then the quest end location actor in a certain sequence. I’ve been playing around with it a lot but getting nowhere. What funny is that if i start the quest, save, and then restart the game (the quest still active because that saves too), it works on restart.

Hopefully that’s a good enough explanation. Below is my logic (i got rid of tick because it scares me haha):

This one should be familiar to you -

Here is how i add/remove the widget itself -

Finally, and promise you won’t laugh, here is how I am handling quests -

as you can see in the third pic, I spawn the quest destination actor, activate the event timer from the first pic, and then call the create widget in the second pic. All three of these images are in the character BP.

I suppose it bears some importance to show you how the quest destination actor operates:

Essentially, once you overlap, it calls the “remove indicator” event in the second pic, closes the branch that allows the event timer from the first pic, and then destroys itself (i tried pause/resume timer but it is buggy). it does not increment the quest number variable, because I’m just pointing people to destinations in the persistent level. the actual event to increment the next quest and start everything all over again happens in a sub-level and is probably another issue for another day.

Sorry for the novel. I hope it’s not too much and I appreciate your excellent help thus far!

You could convert the reference variable into a validated one:

And run the updates only when it’s Valid. And you can invalidate a reference by not plugging anything into it:

image


And, or, invalidate the timer itself:

When the quest target becomes invalid.

Or stop Tick if you’re using that:

image

No Tick = No Problem :innocent:

This does not seem to be doing anything.

image

And this will only work if there’s one quest ever:

image

Validated get! Haven’t used one in a long while but that did the trick! thank you so much for holding my hand through that! :rofl: also yes I have a lot of junk hanging around i need to clean up. I create that quest widget elsewhere now, so you were right, it was not doing anything there. I really appreciate the help!!

1 Like

You’re right! It does get erratic at great distances. Is there something that can be altered to make this behave a little better?

Also, other than that, this is PERFECT!

I just checked “player Viewport Relative” as some googling seems to indicate this may make things better. since I’m top-down, the viewport never rotates on Z, so would this be a pretty acceptable fix?

The effect is so nice, and is what I’m looking for.
I’m not familiar dealing with 2d vector, I can’t understand the blueprint either , my math is bad.so I just copy it for later use…
Thanks.

1 Like

I don’t know how I didn’t get notified of updates to this thread until now. lol. Yay UE forums!
Thanks for the answer Everynone, and for the compliment on the bikes :slight_smile:

1 Like