2D Sprites in the 3d Space

I am learning UE4 and it’s being great. Going through a number of books that I got on fanatical and I am having a good time with it. Maybe I will get to it eventually, but I am anxious to figure out how to make 2D sprites turn towards the player in fps type game. Like the original Doom. I have done a search and I found all sorts of instructions but I cant get it to work. It strikes that the instructions I am finding are way more complicated than need be. Or maybe I’m missing something. If there is an easy(ier) way to do this, and someone would fill me in I would be very appreciative. Thanks all.

I’m brushing up on my UE skills after a year of hiatus, but as far as I remember… You can’t just say “look at screen” for every object type out of the box. I think billboards let you do this though. But, I presume you are using a you need to write your own piece of code to make it happen.

To figure it out, you’ll need to break down what is happening. Let’s start with the first step.
(Q) Where do you want the object to keep facing?
(A) The player camera

(Q) How often should it refresh?
(A) Realtime

That was easy, so how do you refresh on realtime? Inside the actor, you’ll set every tick and make it whatever timing you want. The lower the value, the faster refresh it will be (smoother) at the cost of performance. So if there’s a lot going on, setting the value higher might be worth considering.

From there, you’ll follow the tutorial of casting to the player’s camera, getting its rotation values and setting the inverse of it (I think) to the rotation value of the “sprite” aka billboard you are using.

I made an example for you to follow. Go into your character blueprint and put this in the beginning. You can place it in its own function if you prefer but this is for illustration purposes only.

The name bar is just a TEXT element inside the character blueprint.

The way I figured this out just now is I got the rotator of the camera, broke it, and output its values in print. You can use append to do X: [Value ] Y: [Value] Z: [Value] and plug in those numbers really quickly. Moving the camera around allowed me to determine what X, Y and Z means (camera).

You basically want to mirror everything except X, which doesn’t need to be mirrored. But the value needs to be the same. Y * -1.0 is the inverse of Y. Z + 180 is the inverse of Z. So if it’s 5 degrees, the inverse is 185 degrees.

I’m sure unreal has different ways to go about this but this was the basic math behind it.

Now, if you’re going to do the same but from an external actor, you’re going to need to create a global variable that passes the character object as far as I remember. Maybe it’s already there within the level blueprint? But either way, it’s good to keep player data in a root file called a “game instance”. If you’re unfamiliar with that, there are plenty of tutorials about it. I think WTF has an episode or two on it. Anyway, you just need to get the player and the camera from it. I’m pretty sure you don’t need a game instance to do this, again, I’m rusty. :stuck_out_tongue:

Hope this gets you further along than you were. If you have further questions about this, feel free to ask.

1 Like