[widget blueprint] Arrow that shows an element

Hi,

I am currently developing a small game and I am facing a problem,
In the map I have the player and a tower in which the player has to go, with this I have a blueprint widget that has an arrow and I would like that arrow to point to the tower to tell the player where it is needed That he surrenders, the problem is that I can not do it, can you help me?

cordially,
Nicolas

I decided to help you only because you used “cordially”. :stuck_out_tongue:

First, get the vector from the character to the target location. Then, get the forward vector of the character and add the rotation of this forward vector from the coordinate system base. You have to find out what it is. By doing so the vector will be shifted to be relative to the direction the character is facing. YOu can use the camera forward vector as well.

After you have the rotated target vector, extract ONLY the X and Y components of the vector and use those as the 2D vector of the widget arrow. This will cause the system to point in the correct direction. You might have to rotate the arrow 90*n degrees depending on the rest of your system, so try it once and see if it point towards the target or stays at a fixed angle to the true direction.

HTH

So basically you need to get the location of your player and the target(the Tower).

Than you can probably use this node Find Look at Rotation | Unreal Engine Documentation to get the rotation needed for the arrow and set the rotation.

How deep an answer do you want? I can probably get you the exact blueprint nodes in about an hour, but the hint above might be enough.

By following your instructions I realized this:

The return value goes directly to the widget,

But now that I have this is that right? And that must be added because with my test does not make it so good

(i’m sorry for the french)

en suivant tes instruction j’ai réalisé cela:

139917-temp.png

la valeur retourné va directement sur le widget,

mais maintenant que j’ai cela est ce bien? et que faut il ajouter car avec mon test sa ne rend pas tellement bien

Thank you but could give you an example because it gives the same result, the arrow is moving well but it does not show the tower

No, you have to get the rotation of the forward vector. For example, let us say that your vector starts as <1, 0, 0>. If it is <0, 1, 0> it has been rotated 90 degrees around teh Z axis. You have to find the rotator that corresponds to the forward vector. Vector to Rotator conversions - Feedback for Unreal Engine team - Unreal Engine Forums

Then you can use the node linked below to get the rotational vector pointing towards the tower. Subtract the tower rotator to the forward vector rotator and you have the relative rotator. This rotator when provided as the widget arrows rotator through the node SetRotator will point in the correct position. If you want to show the tower in that direction you have to get the distance of the player to tower vector and set the location to be the center of the widget + PlayerToTowerVector * lengthOfVector.

I did not understand everything I am French and my English is not perfect,
Could you make a quick example to help me? (In picture if you can)
Because I do not see exactly what I have to do,
There I recover the rotation now, and I return a rotator

Thank you very much for your help ^^
I’m still a beginner so I still have some unknown

Here is a working blueprint Set arrow rotation to target posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4

You need to get reference to the Tower(Target) somehow, the way I did it here is I did it in Level Blueprint(On top click on the arrow next to blueprints and open level blueprint), there if you have something selected in the World Outliner you can right click and create reference to it.

I also just placed the arrow component into the world and got the reference the same way and attached it to the actor later on.

This does work ok for me when doing it on event tick, can be probably optimized a bit to not happen on every tick, but well…just a quick example.

Thank you very much but there is a small problem, the widget’s arrow is an image and this blueprint works for the actors,
What changes should I make?

How do you place it into the world? If it is placed into the world you should be able to get a reference and set its rotation anyway.

It is placed in a widget, it is an image,
I have the reference but the images are not considered actors so its not working

You mean an UMG widget?

In that case you either need to expose the image as a variable in the UI and than set its transform(Get HUD node is the start there), or create widget, set render transform and set the In Transform Angle. Both using the rotator you get from the code above.

This is slightly more complicated, are you making a 2D game? I do not think that UMG widged is the ideal solution for this, I would go with a plane that is using the image as a texture.

Okay, in recum, you say it would be better if it was an object directly at stake?
No it’s a 3d game
Yes I must confess not to have understood everything could you explain to me the procedure to follow to realize this?

It depends on what you want it to look like, if it is an arrow like on a minimap than having it as a UMG widget is the solution and that is sadly something I have never done.

If you want to have it like an arrow above the characters head(or in front of it or whatever) than having it as an actor in game is the way and that is what I sent you.

You should have all the information you need at your disposal now, you know how to get the direction to the target using my BP(you can convert this into a vector, by breaking it and making a vector), you can get your character current rotation using what NoobsDeSroobs told you in the other reply. And you can calculate the angle between the two to set the render transform of the UMG widget(Hint:

).

Try to move from here on your own, experiment a bit, best way to learn to be honest.

thanks a lot for your help