I was trying to create a basic arrow cursor that can be present around the centre dot, rotates around the center 360° in a 2D (X & Y) scape (basically screen UI), while pointing towards the highlighted objective in a 3D environment. This environment is full 3D with X, Y and Z axis movement. The player can move and rotate in all directions.
The end goal is to make the arrow below rotate towards the highlighted objective. Right now it rotates, just not towards what I want it to rotate to.
Solution 1 (this one comes really close):
The logic in this one is → I get the location (Vector) of the spawned objective and pass it into the WB of the Screen UI. This is where the calculations happen inside a timer (not using event tick for this). I have a separate WB just for the arrow, which is an image inside a canvas.
In a custom event in the WB Screen UI Event Graph, I just create the WB Arrow and add it to the Screen UI canvas as a child, and then do some technical changes to the arrow like setting anchors, alignment, position and render transform pivot, and then the timer (Set to 0.01 seconds and looping, so frame by frame) starts.
This is where I need help understanding the math and logic of how it should be done:
Initially in the calculations, I get the World location of the player (I am using a pawn here), and subtract that from the ‘vector’ of the spawned objective (yellow line coming in from top) then I make a Vector 2D out of the X and Y and normalize 2D. Same for the camera component in the bottom part.
Then the values are fed into ‘dot’ and broken and multiplied with each other and then subtracted from each other (I don’t get this part, maybe this math is wrong), Atan2 (Radians) and then turned into degrees, which I feed into set render transform angle for the Arrow (got the formula from GPT)
While debugging one by one, I checked that the vectors I was getting were correct, and the end debugging was checking the Degrees, which would always be zero on the spawned objective (so that was mission success kinda), but the arrow would end up not pointing towards the objective. It would instead point upwards on the Z axis (there is a Z axis point where all degrees are present, 180° to 0° to -180°)
So I am not sure how to go about this
Solution 2:
This one is logic where the location of the spawned objective is measured against the Screen UI using ‘Project world location to widget position’.
I don’t know how this one should work, so have put a basic version of whatever I last had, here
If anyone knows a better method do let me know.
Thanks!!